1

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.

amagain
  • 1,936
  • 2
  • 16
  • 32
  • 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 Answers3

1

So in your local git repository do the following:

  1. Take a backup of the repo by creating a new branch or copying the folder
  2. Now use git log and copy the sha of the commit you want to revert to
  3. Use git reset --hard <sha> to reset.
  4. git push origin master -f to push to bitbucket
Bishakh Ghosh
  • 1,082
  • 8
  • 13
1

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.

Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263
0

You can try this put specific commit hash code in last

git reset --hard <commit-hash>
Gohel Dhaval
  • 750
  • 1
  • 7
  • 12