在 rebase 出错后删除其他人在我的分支上的提交 [英] Remove other peoples' commits on my branch after rebase gone wrong

查看:100
本文介绍了在 rebase 出错后删除其他人在我的分支上的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里陷入了一些 git-funk.我需要自己解决这个问题.

I got myself into some git-funk here. I need to git-fu myself out of this.

我加入了一个新团队并创建了一个功能分支:

I joined a new team and created a feature branch:

git checkout -b feature_branch

做了一些更改,然后将它们提交/推送到分支.

Made some changes and then committed/pushed them up to the branch.

git commit -am "Changes"
git push origin feature_branch

有人在我的 PR 上留下了评论,所以我进行了更改,然后在再次提交/推送到该分支之前签出 master 和 rebase 我的分支:

Someone left a review on my PR, so I made the changes, and then checked out to master and rebased my branch before committing/pushing again to that branch:

// from feature_branch make some changes
git commit -am "New changes"
git checkout master
git checkout feature_branch
git rebase origin/master
git push feature_branch

一旦我这样做了,我注意到我的 PR(在 Github 上)发现了其他人的提交.然后我被告知,这个新团队的典型方法是结帐到 master 并合并回我的分支,而不是 rebase.

Once I did this, I noticed my PR (on Github) picked up someone elses' commit. I was then informed that the typical method within this new team is to checkout to master and merge back into my branch INSTEAD of rebasing.

现在是时髦的部分——我开始使用 git reset --hard 并选择我想要的提交,在其他人提交之前.

Here is the funky part now -- I started mucking around with git reset --hard and picked the commit I wanted that was before that commit from someone else.

一切都很好,至少我是这么认为的.然后我把它推上去,它似乎已经从我的 PR 中删除了其他人的提交.

All was well, or so I thought. I then pushed that up and it seemed to have removed that other persons' commit from my PR.

我今天早上检查过,现在有很多其他人的提交被发现了.

I checked this morning and now there are a bunch of other commits from someone else that got picked up.

所以现在我处于这种奇怪的状态.我查看了我的 PR,几乎有 30 次提交(其中 6 次来自不同的人).实际差异(文件更改)只是我接触过的文件,这很好,但历史本身看起来很荒谬.

So now I'm in this weird state. I look at my PR and there are almost 30 commits (with 6 from different people). The actual diff (files changed) are only the files that I touched, which is good, but the history itself looks ridiculous.

清理它的最佳方法是什么?一切都建议使用 git rebase,但是,我被建议不要使用 rebase.

What's the best approach to clean this up? Everything is suggesting to use git rebase, however, I was advised not to use rebase.

不幸的是,我需要保留这个分支.清理它并删除除我之外的所有其他提交的最佳方法是什么?只需将其完全重置,然后将更改挑选回分支?

Unfortunately, I need to keep this branch. What's the best way to clean it up and remove all the other commits except only mine? Just reset it completely and then cherry-pick the changes back onto the branch?

请帮忙:|

这是历史记录的示例:

Commits on Jul 30, 2018
<SOMEONE ELSES>

Commits on Jul 31, 2018
<SOMEONE ELSES>
<MY ORIGINAL COMMIT>
<SOMEONE ELSES>

Commits on Aug 1, 2018
<SOMEONE ELSES>
<MY COMMIT [Merge branch master into my feature branch]>
<MY COMMIT>
<SOMEONE ELSES>
<MY COMMIT>
<MY COMMIT>
<SOMEONE ELSES>
<MY COMMIT>

etc etc

推荐答案

清理内容的最佳选择可能是使用 git rebase -i 来重新基于分支中已有的更改1 在您要清理的所有内容之前,然后从编辑器的更改列表中删除您不想要的更改(只留下您想要的更改).这将重写更改以仅包含您的更改,并使您回到干净"(相对)状态.

Your best bet to clean stuff up is probably to use git rebase -i to rebase on a previous change already in you branch1 before all the stuff you want to clean up, and then delete the changes you don't want from the list of changes in the editor (leaving just the changes you do want). That will rewrite the changes to include just your changes and get you back into a "clean" (relatively) state.

完成此操作后,您可以按照 git 流程的建议从 master(或任何地方)git merge.

Once you've done that, you can then git merge from master (or wherever) as recommended by your git flow.

1如果您想清除之前重新定位/合并到您的分支中的所有内容,或者可能是稍后的refpoint,则可能是您最初分支的更改.您选择的点越早,您(可以)清理的东西就越多,但您可能需要做的工作也就越多.

这篇关于在 rebase 出错后删除其他人在我的分支上的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆