1

I have the following history in git

A-B-C-D-E-F 

I want to rollback the changes that I did in commit E, but wanted the changes that I in commit F. So I did a git rebase like this

git rebase -i D 

and picked only commit F and ignored commit E. My history now looks like

A-B-C-D-F 

But, what I want to do is, rollback the changes done in commit E, but still maintain in history that E was added and then removed. Something like this

A-B-C-D-E-F-E1 

Where E1 is a commit which reverts the changes done by commit E.

How to do it in git?

3 Answers 3

4

git revert $SHA_FOR_E will make a new commit "the opposite of" commit E.

From the man page:

Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I read about revert, but some how got confused with rebase
2

I don't think rebase would be the way to go. My first suggestion would be to use revert

git revert E 

This will create a new commit reverting that E was applied

Another option would be to just reverse the patch.

git show E | patch -R -p1 && git commit . 

will reverse what was done in E.

Comments

2

You use the revert command. This creates a commit that it is the inverse of the SHA provided.

git revert <SHA E>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.