0

I'm facing i want to remove my commit from main repository. the code has pushed with my unwanted local changes. So how can i revert back that. i'm using source tree and git as well. please help me.

BJ Myers
  • 6,617
  • 6
  • 34
  • 50
srini
  • 13
  • 6

1 Answers1

2

Try git revert. It doesn't change history, but "unmakes" a single commit by applying the reverse actions to the source as a new commit.

You can specify a range of commits for revert with the .. syntax (detailed explanation):

git revert -n abcd1234..fedc0987

(The n flag prevents autocommits. abcd... stands for a unique commit ID hash.)

Sascha Wolf
  • 18,810
  • 4
  • 51
  • 73
ojrask
  • 2,799
  • 1
  • 23
  • 23
  • what is that abcd124 means? is that means commit id? – srini Jan 12 '15 at 06:05
  • Oh, those are commit identifier hashes. By using `git log` in the terminal you can see the unique hash for each and every commit in the Git repo. On Source Tree there should be unique hashes in each commit's info somewhere I presume. I used `abcd...` as an example. – ojrask Jan 12 '15 at 06:06
  • Yes, the unique commit id hash. – ojrask Jan 12 '15 at 06:07
  • Commit: f6341b46f76ddc1d6a7d2b387f780a101d7850a8 .... are u mentioning this? – srini Jan 12 '15 at 06:07
  • fine thanks. will it remove my changes from main repo? – srini Jan 12 '15 at 06:07
  • It will remove the commit changes from the branch you're on. If the commit doesn't exist on a certain branch, the `revert` will not work. Once the command is executed, just push the new commit (result of `revert`) to the main repo and it will act like any normal commit. The good side of this is a that `revert` doesn't undo history so your team members can use the new commit without headaches. – ojrask Jan 12 '15 at 06:10
  • won't it be affected the other commits after commited mine? – srini Jan 12 '15 at 06:14
  • Yes and no. Yes as in others can undo the changes of your undo-commit (which used `revert`). No as in `revert` prevents conflicts in history and content. – ojrask Jan 12 '15 at 06:20
  • 1
    @ojrask For a detailed explanation for the "range of commits" syntax (`..`) take a look at [this chapter](http://git-scm.com/book/it/v2/Git-Tools-Revision-Selection) from the progit book. I've also edited the answer with the reference. – Sascha Wolf Jan 12 '15 at 09:03