Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rollback everything to previous commit

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

like image 270
captainrad Avatar asked Mar 12 '14 22:03

captainrad


3 Answers

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

like image 200
0xcaff Avatar answered Nov 14 '22 16:11

0xcaff


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!

like image 34
Sidd Thota Avatar answered Nov 14 '22 14:11

Sidd Thota


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.
like image 2
Rui Meneses Avatar answered Nov 14 '22 16:11

Rui Meneses