Question

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 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

Was it helpful?

Solution

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

OTHER TIPS

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!

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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top