Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert/remove specific Git commit on specific branch using SourceTree?

I use BitBucket and SourceTree. I have two branches called Dev_1.2.2 and Dev_1.2.3

I committed some files on Dev_1.2.2 but did not push. I don't want to commit or push these files on Dev_1.2.2, I made commit successfully thus files on Dev_1.2.3 but can't revert/remove the commit from Dev_1.2.2.

How can I revert this commit from the branch using SourceTree?

like image 216
Jakir Hosen Khan Avatar asked Sep 15 '26 22:09

Jakir Hosen Khan


2 Answers

Not entirely sure what you're asking but I can see two options:

Reverse the commit

To reverse the specific commit in SourceTree, do the following:

  • Check out the Dev_1.2.2 branch by double-clicking it in the list of branches on the left.
  • In the commit history graph, select the commit in question.
  • Right-click the commit, and select "Reverse commit..." from the context menu.
  • Confirm the action in the displayed confirmation dialog.

That should do it, it will create a reversal commit. Your history will now show that you first added the files, and then a second commit showing that you removed them again.

Reset to previous commit

If you want to get rid of the whole commit without it showing in history, you can reset the branch to the commit before you added the files.

To do that, you need to do the following:

  • Check out the Dev_1.2.2 branch by double-clicking it in the list of branches on the left.
  • In the commit history graph, find the commit in question.
  • Next, select the commit immediately before you added the files. Make sure it's in the same branch.
  • Right-click that commit, then select "Reset Dev_1.2.2 to this commit".
  • In the next dialog, select the "Hard" option and confirm the action.

Warning: This will mean you lose any changes made after the selected commit. Your branch will be reset to this commit.

like image 120
nwinkler Avatar answered Sep 18 '26 15:09

nwinkler


You can use "Rebase children of [commit hash] interactively" on a commit that is below the one you want to delete.

Then use "delete selected".

Note, this rewrites the commit date, which you can fix from command line using git rebase --committer-date-is-author-date [commit hash].

After rebase, you will need to git push --force.

like image 35
EpicPandaForce Avatar answered Sep 18 '26 16:09

EpicPandaForce