I have committed changes in my bitbucket
account 4 times in last 2 days, but now I want to go back to the state that was 2 day back. If there is any way, then please help me out. I am using Source tree if that helps my quest.

- 2,042
- 2
- 20
- 36

- 99
- 2
- 11
-
Hello You can use SHA code or commit code and use hard reset of git with specific commit key – Gohel Dhaval May 23 '17 at 05:33
-
Possible duplicate https://stackoverflow.com/questions/14872486/retrieve-specific-commit-from-a-remote-git-repository – Jabaa May 23 '17 at 05:34
3 Answers
So in your local git repository do the following:
- Take a backup of the repo by creating a new branch or copying the folder
- Now use
git log
and copy the sha of the commit you want to revert to - Use
git reset --hard <sha>
to reset. git push origin master -f
to push to bitbucket

- 1,205
- 9
- 17
If the branch in question is not shared (i.e. you are the only one using it), then you can try nuking the commits which occurred in the past 2 days, for example:
git reset --hard HEAD~2
Replace the 2
with the actual number of commits you want to remove. To see how many commits you do want to remove, you can type git log
on your branch. Note that to push the branch back to Bitbucket you would need to use:
git push --force origin yourBranch
If the branch in question is shared, then the above option is not recommended, because it will rewrite the history of that branch which can cause problems for anyone who is sharing it. Instead, you can try reverting the commits from the last two days:
git revert A^..B
where A
is the earliest commit you want removed and B
is latest commit, presumably the current HEAD
of your branch. Functionally speaking, doing a git revert
is the same as removing the commits. But in practice, revert adds new commits on top of your branch to undo previous ones, and this is safe for a shared branch.

- 502,043
- 27
- 286
- 360
You can try this put specific commit hash code in last
git reset --hard <commit-hash>

- 820
- 1
- 8
- 12