1. 正常做项目:
git clone http://.....
git checkout your-dev-branch
scp -p -P port userid@ipaddress:hooks/commit-msg .git/hooks/
export EDITOR=vim
edit source code
git add . / git rm filepath
git commit .
edit commit-msg
git push -u origin your-dev-branch
2. 别人打了comment,自己需要打patch
fix comment issue
git add ./git rm filepath
git commit --amend
change commit-msg if necessary
git push -u origin your-dev-branch
3. 打算合并自己的代码,但是期间其他人合并了代码,需要修正conflict
git pull --rebase
fix conflict code
git add . / git rm filepath
git rebase --continue
git commit --amend
change commit-msg if necessary
git push -u origin your-dev-branch
4. 在别人的代码上打patch
git clone http://.....
git fetch ssh://userid@hostname:port/gitpath refs/changes/num1/num2/num3 && git checkout FETCH_HEAD
scp -p -P port userid@ipaddress:hooks/commit-msg .git/hooks/
export EDITOR=vim
fix source code
git add ./git rm filepath
git commit --amend
change commit-msg if necessary
git push -u origin your-dev-branch
5. 将当前提交的开发代码片段搬到主分支,直接使用git cherry pick,注意只是当前提交的代码片段,而不是当前所有的差异代码
6. 将目前所有差异代码合并入主分支
git clone http://.....
git fetch ssh://userid@hostname:port/gitpath refs/changes/num1/num2/num3 && git checkout FETCH_HEAD
scp -p -P port userid@ipaddress:hooks/commit-msg .git/hooks/
export EDITOR=vim
git checkout dev-branch
git reset --hard
git pull
git checkout master
git reset --hard
git pull
git reset --hard origin/master
git merge --no-ff --no-commit dev-branch
fix conlict code
git add . / git rm filepath
git commit . (可能会报错fatal: cannot do a partial commit during a merge)
如果报错则需要git commit -i * .
git push -u origin master
7. 放弃当前改动的代码
git reset --hard ----放弃所有文件改动
git pull
git checkout filepath ----放弃某一个文件改动