提交代碼
每次提交代碼前,先執行? git pull --rebase ,確保已經合并天上代碼,解決沖突
git add
git commit -m
git push origin HEAD:refs/for/{BRANCH_NAME}
可考慮設置 alias 方式,參考下文
CR-2 情況處理(verify-1情況一樣處理)
d794693 2015-11-12 (HEAD -> master) commit 7 [lvgx]
f1bbc51 2015-11-12 commit 6 [lvgx]
d813cd8 2015-11-12 commit 5 [lvgx]
cc00834 2015-11-12 commit 4 [lvgx]
ad1fdac 2015-11-12 commit 3 [lvgx]
12baec9 2015-11-12 commit 2 [lvgx](CR-2) 代碼有問題的commit點
9c95373 2015-11-12 commit 1 [lvgx]
如果需要修改commit 2 提交點內容,重新提交;
1、rebase
git rebase -i HEAD~6 or git rebase -i 9c95373(目標點前一個點)
pick 12baec9 commit 2
pick ad1fdac commit 3
pick cc00834 commit 4
pick d813cd8 commit 5
pick 2982c6d commit 6
pick 264870e commit 7
Rebase 9c95373…264870e onto 9c95373 (6 command(s))
Commands:
p, pick = use commit
r, reword = use commit, but edit the commit message
e, edit = use commit, but stop for amending
s, squash = use commit, but meld into previous commit
f, fixup = like “squash”, but discard this commit’s log message
x, exec = run command (the rest of the line) using shell
These lines can be re-ordered; they are executed from top to bottom.
If you remove a line here THAT COMMIT WILL BE LOST.
However, if you remove everything, the rebase will be aborted.
“~/Desktop/gerrit/test2/matchbox-app-android/.git/rebase-merge/git-rebase-todo” 24L, 747C
2、將commit2的pick修改為“edit”
pick 12baec9 commit 2 為 edit 12baec9 commit 2
保存退出
xz@xzdeMacBook-Pro:matchbox-app-android$ git rebase -i 9c95373
Stopped at 12baec9f5a1f3611ba071c59548f20ab3279dbb9… commit 2
You can amend the commit now, with
git commit --amend Once you are satisfied with your changes, rungit rebase --continue
3、修改代碼,執行
git add .
git commit --amend
4、git rebase --continue
5、git review
Abandon 情況處理
commit一但出現abandon,這個changeid將不再允許commit
xz@xzdeMacBook-Pro:~/Desktop/gerrit/test3/matchbox-app-android$ git push riv
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 337 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2)
remote: Processing changes: refs: 1, done
To ssh://lvgx@192.168.14.217:29418/matchbox-app-android
! [remote rejected] HEAD -> refs/for/master (change http://192.168.14.217:8281/132 closed)
error: failed to push some refs to ‘ssh://lvgx@192.168.14.217:29418/matchbox-app-android’
此時需要新建一個commit實現代碼提交,執行reset操作
1、git reset
xz@xzdeMacBook-Pro:~/Desktop/gerrit/test3/matchbox-app-android$ git reset 1876441
Unstaged changes after reset:
M commit3
xz@xzdeMacBook-Pro:~/Desktop/gerrit/test3/matchbox-app-android$ git st
On branch master
Your branch is ahead of ‘origin/master’ by 13 commits.
(use “git push” to publish your local commits)
Changes not staged for commit:
(use “git add …” to update what will be committed)
(use “git checkout – …” to discard changes in working directory)
modified: commit3
no changes added to commit (use “git add” and/or “git commit -a”)
2、git commit
xz@xzdeMacBook-Pro:~/Desktop/gerrit/test3/matchbox-app-android$ git commit -am “commit52+”
[master 3cb427e] commit52+
1 file changed, 1 insertion(+)
3、pull
建議每次review之前 運行 git pull --rebase
git pull --rebase
4、git review
沖突情況處理
沖突情況出現,說明其他人做了相同文件的修改,且優先入庫了;
先 commit 本地內容只本地倉庫
執行 git pull --rebase 操作,合并天上內容
修改 rebase 過程中遇到的沖突問題
執行 git review 操作
別名設置
配置多branch情況建議配置config文件
cd ~
vim .gitconfig
添加
[alias]
review = !sh -c ‘git push origin HEAD:refs/for/$1’ -
review 分支使用
git review branch-name
reset 介紹
type Index WorkDir WD safe
soft NO NO YES
mixed YES NO YES
hard YES YES NO
–mixed reset HEAD and index
–soft reset only HEAD
–hard reset HEAD, index and working tree