I have been facing some issues regarding my master branch. I accidentally pushed some commits to my master branch which were really old.
Now I want my master and source to go back to a previous commit (highlighted with blue color in the picture) and discard all the other commits after that from the source and history so that I can push my new commits after that. I am using bitbucket
and SourceTree
.
How would you do this?
It is best to create a new commit which will be the exact image of the old 'Booking' one:
First:
Then:
Now that the working tree represents the right content:
That way, no
filter-branch
(which would rewrite the history), norevert
(which might be complex when a merge is involved).To know more about the "reset magic", read "Reset Demystified"
The first
reset --hard
restore the right content (but also moves HEAD and reset index)The second
reset (--mixed)
will restore HEAD to its original place, and will restore the index as well. But it will leave the working tree untouched.That way, there is a difference between
master
index and the working tree, which represents the content of the old commit.Adding and committing are enough to create a new commit on top of the current
master
, with the old commit content.