美文网首页
git常用操作

git常用操作

作者: 大头菜turtle | 来源:发表于2019-10-11 14:44 被阅读0次

龟龟是最可爱的猫

git clone URL

git clone URL通常只会克隆一个分支,那么如何clone所有分支呢?

git branch -v
* master 093df85 init commit

可以查看到只有一个分支

通过

git branch -a

则可以查看所有隐藏分支

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/testbranch

如果需要在某个分支上工作,需要

git checkout -b testbranch origin/testbranch
Branch testbranch set up to track remote branch testbranch from origin.
Switched to a new branch 'testbranch'

现在再查看

 git branch -v
  master     093df85 init commit
* testbranch 2bdf3c3 test

可以看到testbranch,且可以在该分支开发

git push 出现 remote error:

remote: error: refusing to update checked out branch: refs/heads/dev
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To /media/zym/zym-usb/grayscale/
 ! [remote rejected] dev -> dev (branch is currently checked out)
error: failed to push some refs to '/media/zym/zym-usb/ggg/'

Solution:

git config receive.denyCurrentBranch ignore

git 放弃工作区/暂存区/修改

  1. 文件已修改,还没有add 使用git checkout -- fileA 可以撤销git在工作区的修改
  2. 文件已经修改并且add进暂存区,分两步:先用 git reset <文件名> 撤销 git add 操作(此时更改仍留在工作区),再执行 git checkout -- 文件名 清除工作区的改动
  3. 修改后,文件放入暂存区,且文件再次修改:分三步:先用 git checkout -- 文件名 撤销工作区的改动,再用 git reset <文件名> 撤销 git add 操作(此时更改仍留在工作区),最后执行 git checkout -- 文件名 清除工作区的改动

通过 git checkout -- 文件名 命令可以撤销文件在工作区的修改。
通过 git reset 文件名 命令可以撤销指定文件的 git add 操作,即这个文件在暂存区的修改。

git clone with submodules

git clone --recurse-submodules

相关文章

  • 组件化(第一篇)

    组件化 git 常用操作指令 cocoapods的基本使用 cocoapods本地私有库 一、git 常用操作指令...

  • git的常用操作

    git的常用操作

  • GIt 操作补充

    常用的git操作命令 常用的git操作命令已经能够满足日常的工作需求 现补充一些高级命令 git branch -...

  • git使用整理

    git使用常用操作-常用基本命令 克隆:git clone 【url】 查看修改状态: git status (g...

  • GIT 版本管理 常用命令

    Git 常用命令流程图 Git常用操作命令: 初始化创建:$ git init //检出仓库:$ git clon...

  • 🍏常用 git 操作指北

    ? 常用 git 操作指南 ? git图形界面操作软件 ? 开发流程 git clone 拉取项目代码,不必多说 ...

  • git常用操作 🎀

    git常用操作 ? 基本知识 查看git信息 修改git配置 提交类操作 分支类操作 创建分支 查看分支 修改分支...

  • git常用操作命令

    git常用操作命令 1 git工作原理图 2 git远程操作 2.1 git clone 远程操作的第一步,通常是...

  • 真 git 操作大全 不会就看

    git 常用命令git 远程操作git 撤销操作 推酷git大全 react router4 中文文档 koa 简...

  • git常用操作

    git缩写配置: 在.gitconfig文件中添加: [alias] git常用操作: git clone 克隆一...

网友评论

      本文标题:git常用操作

      本文链接:https://www.haomeiwen.com/subject/sygtmctx.html