How to rollback everything to previous commit

GitGit CommitAtlassian Sourcetree

Git Problem Overview


Recently in a project with multiple people, a commit was made as seen in the image below. Marked in red you can see a commit with the description/comment of 'Merge?'.

This commit added numerous files and altered numerous others and was never intended to take place.

Using [tag:atlassian-sourcetree] what do I need to do to roll everything back to the commit highlighted in blue? (I am 8 commits behind as seen in the screenshot.)

sourcetree troubs

Git Solutions


Solution 1 - Git

If you have pushed the commits upstream...

Select the commit you would like to roll back to and reverse the changes by clicking Reverse File, Reverse Hunk or Reverse Selected Lines. Do this for all the commits after the commit you would like to roll back to also.

reverse stuff reverse commit

If you have not pushed the commits upstream...

Right click on the commit and click on Reset current branch to this commit.

reset branch to commit

Solution 2 - Git

I searched for multiple options to get my git reset to specific commit, but most of them aren't so satisfactory.

I generally use this to reset the git to the specific commit in source tree.

  1. select commit to reset on sourcetree.

  2. In dropdowns select the active branch , first Parent Only

  3. And right click on "Reset branch to this commit" and select hard reset option (soft, mixed and hard)

  4. and then go to terminal git push -f

You should be all set!

Solution 3 - Git

There are two options to revert one commit our merged branch.

A. Using sourcetree

  • Right click in commit
  • Select reverse commit
  • Sometimes, it can be failed. In that case, please try option B.

B. Using terminal

  • Select your commit and look info on bottom side of screen. Example commit id: 1a6cd9879d8c7d98cdcd9da9cac8979dac7a89c

  • Click top right corner "Terminal" option of Sourcetree.

  • Write in terminal: git revert your_commit_id -m 1

  • When the commit message editor opens up:

    • For just accept and exit, write :q then click enter.
    • If you want to change the commit message, press "i", write your message and then write :wq click enter.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncaptainradView Question on Stackoverflow
Solution 1 - Git0xcaffView Answer on Stackoverflow
Solution 2 - GitSidd ThotaView Answer on Stackoverflow
Solution 3 - GitRui MenesesView Answer on Stackoverflow