1:git分支
1)查看當前的遠程庫
$ git remote -v
2)push分支到服務器,如果你有個叫serverfix的分支需要和他人一起開發,可以運行git push (遠程倉庫名) (分支名)
$ git push origin serverfix
接下來,當你的協作者再次從服務器上獲取數據時,他們將得到一個新的遠程分支origin/serverfix:
$ git fetch origin
$ git chechout serverfix
2:新建標籤
a)創建一個含附註類型的標籤非常簡單,用 -a
(譯註:取 annotated
的首字母)指定標籤名字即可:
$ git tag -a v1.0 -m 'update to v1.0'
而 -m
選項則指定了對應的標籤說明,Git 會將此說明一同保存在標籤對象中。如果沒有給出該選項,Git 會啓動文本編輯軟件供你輸入標籤說明。
b)可以使用 git show
命令查看相應標籤的版本信息,並連同顯示打標籤時的提交對象。
$git show v1.3
我們可以看到在提交對象信息上面,列出了此標籤的提交者和提交時間,以及相應的標籤說明。
c)輕量級標籤
輕量級標籤實際上就是一個保存着對應提交對象的校驗和信息的文件。要創建這樣的標籤,一個 -a
,-s
或 -m
選項都不用,直接給出標籤名字即可
$ git tag v1.4-lw
$ git tag
v1.2
v1.3
v1.4-lw
3:Git中的着色
$ git config --global color.ui true設置好以後,當輸出到終端時,Git 會爲之加上顏色
4:恢復刪除文件
$ git checkout 47a08b4a7b38ab963dade11e024839fd396e7423 -- device/amlogic/PI3100_93/mali.ko
5:比較2個分支目錄
$git diff T852..T852-SBK frameworks
6.
剛配置好的git倉庫服務器,首次提交的時候會報如下錯誤:
remote: error: refusing to update checked out branch: refs/heads/master
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: To squelch this message and still keep the default behaviour, set remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. To ... ! [remote rejected] master -> master (branch is currently checked out) error: failed to push some refs to
需要配置一下git的接收配置,執行如下命令即可正確提交:
# git config receive.denyCurrentBranch ignore
7:查看某次commit的詳細記錄,包括修改了哪些文件,該文件修改了哪些地方
# git show 7b0778531938e3fffb7a416e9f48c21c0785f586
8:恢復到某次的commit
# git checkout c039249d5085ff301a742a07230e1f3e1748acb8 -- device/amlogic/MID30801/version_id.mk
# git add device/amlogic/MID30801/version_id.mk
# git commit -m 'AP6476恢復wl212'
9.從一個git倉庫遷移到另外一個git倉庫
git push --mirror [email protected]/username/newproject.git