问题
I am working with a remote branch in git. Before doing any work, I do a git pull to get the ToT. When I look at the git log, I see that this automatically creates a merge commit with a message: "Merge branch 'master' of ssh://myserver:1111/mybranch". Then, I do my work and commit my change. After that I push my change up. Our system is setup with gerrit for code review. My new change shows up in gerrit with dependency on the merge commit. How do I get rid of this?
回答1:
It is likely that the merge has not been fast-forward because your branch had differences with remote one before pulling. So, when you pushed your change, it has probably created more than one chnage for revision in gerrit, right?
The best approach in the work with gerrit is to do a clean checkout of remote branch before commiting and pushing any new change, in which case your change will not have any dependencies. I usually checkout a new branch for each new feature or fix I need to push and keep them until they were verified and merged to master repo in gerrit (just in case it will be needed to change something as result of revision and create a new patchset for the same change).
However, dependencies are useful if you push more than one commit at the same time and the last commit requres the previous one, say if you added two commits to the clean branch anf pushed them, they will appear in gerrit as two changes with dependency between the latest and the previous, and the latest will commit never be merged to master repositary before the dependant.
回答2:
git pull
is actually git fetch
and git merge
if the local branch is remote tracking. So if the remote branch is not fast-forwardable then git pull will create a merge commit. To avoid merge commits use
'git fetch'
'git rebase -p'
'git pull --rebase'
or set the
merge.ff
with valueonly
in the git config.
Or
disable the remote tracking settings from the local branch
git config --unset branch.<branch>.merge
来源:https://stackoverflow.com/questions/7367147/git-remote-merge-commit-causing-false-dependencies-in-gerrit