简体   繁体   中英

Git revert a commit and add changes even after more commits followed

My use case is very usual.

I added a commit, that went through my build system. Some post-commit tests on the build system failed. The system is configured to revert such a commit.

So the System also added a Reverting back revision my-commit .

Now, I added the fixes to correct the build. But someone else made 2 commits on top of the revert that went in successfully before I could push in mine.

So now my state is:

$ git log

commit good-commit1 
author: good-dev1
...

commit good-commit2
author: good-dev1
...

commit good-revert-commit
author: system
...

commit my-bad-commit
author: me
...

Both good-commit1 and good-commit2 change files which I modified in my-bad-commit .

How do I add my fixes on top of my-bad-commit , or revert the good-revert-commit and add fixes on it, and then re-apply the other dev's good commits?

Note : our system doesn't allow -f (force push) to the master branch.

Just revert the revert with

git revert good-revert-commit -n

-n is a synonym for --no-commit here.

So the changes will be in the index, then git add your additional changes, finish the commit and push.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM