I have a git repository that looks like this:
A -> B -> C -> D -> HEAD
I want the head of the branch to point to A, i.e. I want B, C, D, and HEAD to disappear and I want head to be synonymous with A.
It sounds like I can either try to rebase (doesn't apply, since I've pushed changes in between), or revert. But how do I revert multiple commits? Do I revert one at a time? Is the order important?
That will act as a revert for all of them at once. Give a good commit message.
If you want to temporarily revert the commits of a feature, then you can use the series of following commands.
Here is how it works
git log --pretty=oneline | grep 'feature_name' | cut -d ' ' -f1 | xargs -n1 git revert --no-edit
None of those worked for me, so I had three commits to revert (the last three commits), so I did:
Worked like a charm :)
In my opinion a very easy and clean way could be:
go back to A
point master's head to the current state
save
Clean way which I found useful
This command reverts last 3 commits with only one commit.
Also doesn't rewrite history.
For doing so you just have to use the revert command, specifying the range of commits you want to get reverted.
Taking into account your example, you'd have to do this (assuming you're on branch 'master'):
This will create a new commit in your local with the inverse commit of B, C and D (meaning that it will undo changes introduced by these commits):