0

I merged into the main master branch of my git tree a feature that was half-baked. Later, I made a couple of commits in "master" that affected completely unrelated files. All of this has been pushed to remote as well.

Now I want to revert the changes made in that half-baked feature, but without losing the later commits. How can I do that?

1 Answer 1

1

You can checkout the files affected by the half baked feature to the commit before you merged.

# find the commit hash with git log # checkout those files to the commit you want git checkout c5f567 -- file1/to/restore file2/to/restore # commit to master 
Sign up to request clarification or add additional context in comments.

4 Comments

I just did that, but it doesn't seem to do anything. The affected files are still in their "affected" state. I want them to be reverted to how they were in "master", before being merged.
If they are still in their affected state then you didn't check them out to a healthy commit. Did you run git checkout or did you run git checkout <hash> -- file1/to/restore file2/to/restore? Did you check them out to a commit that is far enough back (before the merge?)
I did the second... but wait. Now I realise that I have to check them out to the previous commit to the merge, not the one of the merge. Sorry; I'll try again.
You can checkout the files affected by the half baked feature to the commit before you merged.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.