开发者

git remote merge commit causing false dependencies in gerrit

开发者 https://www.devze.com 2023-04-03 17:10 出处:网络
I am working with a remote branch in git. Before doing any wor开发者_开发问答k, 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

I am working with a remote branch in git. Before doing any wor开发者_开发问答k, 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?


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.


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 value only in the git config.

Or

disable the remote tracking settings from the local branch git config --unset branch.<branch>.merge

0

精彩评论

暂无评论...
验证码 换一张
取 消