git常用操作


龜龜是最可愛的貓

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'

現(xiàn)在再查看

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

可以看到testbranch,且可以在該分支開發(fā)

git push 出現(xiàn) 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 放棄工作區(qū)/暫存區(qū)/修改

  1. 文件已修改,還沒有add 使用git checkout -- fileA 可以撤銷git在工作區(qū)的修改
  2. 文件已經(jīng)修改并且add進暫存區(qū),分兩步:先用 git reset <文件名> 撤銷 git add 操作(此時更改仍留在工作區(qū)),再執(zhí)行 git checkout -- 文件名 清除工作區(qū)的改動
  3. 修改后,文件放入暫存區(qū),且文件再次修改:分三步:先用 git checkout -- 文件名 撤銷工作區(qū)的改動,再用 git reset <文件名> 撤銷 git add 操作(此時更改仍留在工作區(qū)),最后執(zhí)行 git checkout -- 文件名 清除工作區(qū)的改動

通過 git checkout -- 文件名 命令可以撤銷文件在工作區(qū)的修改。
通過 git reset 文件名 命令可以撤銷指定文件的 git add 操作,即這個文件在暫存區(qū)的修改。

git clone with submodules

git clone --recurse-submodules
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容