开发者

How to insert removed commits before my commits, and revert those removed commits?

I tried to split a big commit which was already pushed in a smaller one following How can I split up a Git commit buried in history?. Now, I made some other changes as well and discarded some useless modifications.

Now I tried a push request, but it failed because I've accidentally removed those commits during rebasing instead of reverting them. git status shows:

$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 15 and 2 different commit(s) each, respectively.
#
nothing to commit (working directory clean)

I already tried cloning the repository, reverting that commit and pushing it. Next, I pulled upstream in my working directory. That does not work and is basically applying my new modifications and then reverting everything again to the old state.

How can I insert those 2 commits 开发者_开发问答(fast-forward?) before my commits with a revert commit after it? Do I need to do another rebase?

My commits looks like this:

A - B - C         origin/master
     \
      D - E - F   local working copy

I want it looks like this:

A - B - C - revert_B - D - E - F


Yes, you just need another rebase. If master is at F, then do something like this:

git checkout -b tmp origin/master
git revert B
git rebase tmp master
git branch -d tmp
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜