Git command简介
Git is a distributed version control system originally developed to manage Linux source codes.
Using Git, you can easily view the revision history of your source code to track changes and easily go back in time to learn about the differences between different versions of your files.
Gerrit provides web based code review and repository management for the Git version control system.
git clone: Clones a repository into a newly created directory
git push and git pull:
•git push updates remote refs using local refs, while sending objects necessary to complete the given refs.
•git pull incorporates changes from a remote repository into the current branch
•git pull = git fetch + git merge
git add, git commit, git reset, git checkout
git merge: Join two or more development histories together
git rebase: Reapply commits on top of another base tip
Git merge VS git rebase
特别说明一下git cherry-pick命令:
cherry-pick可以将一个git patch cherry-pick到另外一个分支(branch),另外如果gerrit上有很多还没有merge的gerrit的时候,你想在你的本地获取这个patch的时候可以用cherry-pick命令。git pull不仅会把当前patch的内容抓取下来,还会把其parent的内容也会抓下来。
最后说一下如何解决conflict,场景
A提交了一笔gerrit 1在review,B提交了一笔gerrit 2也在review,但是A和B同时修改了文件x.java的同一行,且gerrit1先于gerrit 2 merge了,此时gerrit 2是无法merge的,因为有conflict。为了解决冲突,B需要现在本地用git pull把server上的commit抓取下来,此时gerrit 1会被抓取到本地,然后打开gerrit 2,选择download-> cherry-pick,复制该命令,然后将patch抓取到本地,再用git status查看哪些文件有冲突,然后用编辑工具搜索=======,找打冲突点,fix 所有的冲突后,git add filename,然后用git commit,接着用git push