Missing dependency in Gerrit

北战南征 提交于 2019-11-30 23:19:51

You need to remove the two unwanted commits corresponding to the abandoned changes from the ancestry of commit 4, i.e. the desired state is for git log to only list commits 4 and 1. When that's done, pushing a new patch set should remove the stated dependency. Getting rid of commits 2 and 3 can be done in many ways, including

  • doing an interactive rebase (git rebase -i HEAD~4 and deleting the lines for the two commits you don't want), or
  • starting a new branch based on the tip of the upstream branch and cherry-picking commit 4.

Ok, here is my revised answer

Starting point is where you have your 4 commits in a row:

#git log --graph --decorate --oneline
* 448fd95 (HEAD, master) Change 4
* 3950f5f Change 3
* 8753adf Change 2
* cdcfe20 Change 1

Next, create a temp branch from the head

#git branch temp
#git log --graph --decorate --onelin
* 448fd95 (HEAD, temp, master) Change 4
* 3950f5f Change 3
* 8753adf Change 2
* cdcfe20 Change 1

Now you need to reset your master to get rid of the unwanted history:

#git reset --hard cdcfe20
HEAD is now at cdcfe20 Change 1
#git log --graph --decorate --oneline
* cdcfe20 (HEAD, master) Change 1

Cherry pick your change 4 into the master

#git cherry-pick 448fd95
[master 19c5ba1] Change 4
 1 file changed, 1 insertion(+), 1 deletion(-)
#git log --graph --decorate --oneline
* 19c5ba1 (HEAD, master) Change 4
* cdcfe20 Change 1

Now you can push the last change to gerrit and your dependencies are fixed

Balachandar

I used the answer from Magnus and did the interactive rebase and removed my previous commit but still had some merge conflicts. Then I manually updated the files to resolve the conflicts.

Finally added the modified files, then ran "git rebase --continue" to resolve the issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!