Reputation: 763
I have 3 commit: master -> v1 -> v2 Inside v1 we found problems and decided to discard all changes in it. How I can reset this changes in v2 ?
I tried switch to branch v1 and run "git reset --hard HEAD^". What the next step? I tried now checkout to v2 and merge it with v1, but it does`t work.
Upvotes: 1
Views: 67
Reputation: 521249
Most likely you would want to use git revert
here:
# from your branch
git log
Find the SHA-1 hash of the v1
commit and record it somewhere. Then revert:
git revert abc123
This will add a new commit on top of your branch which functionally undoes whatever changes the v1
commit introduced.
Note that a hard reset won't work here, not without also nuking the v2
commit, because all it can do it move the HEAD
and all other pointers back some number of commits. If you wanted to go the route of rewriting your history to remove v1
, then an interactive rebase could do that. But in general rewriting the history of a Git branch is not desirable, assuming that branch be already public and possibly in use by other users.
Upvotes: 2