Git rollback my commits
I commit my and push them to Git.
My colleagues commit their changes.
I commit more of my changes.
I have been told that my changes cannot be tested for
This release and have to go in the next release. I have to back out all my changes and only my changes. How can I do that?
I use tortoise when pushing or puling my changes into Git. I am using windows XP machine.
Yes, I pulled my colleagues work before pushing my commits.
I have to mention though that my changes were for completely different files. None of my colleagUes touched them.
It is just one branch, which is the integration branch.
2 Solutions collect form web for “Git rollback my commits”
Why simply not using the
git revert command ?
Lets say initial integrated Repo is I and when your commit is Y and later your collegues commit is C. So may be the line of development looks like this. And the file system is F at present.
(F) I--Y--C1--C2 ↑ HEAD
And as you mentioned
I have to mention though that my changes were for completely different
files. None of my colleagUes touched them.
So you could keep on doing reset HEAD~1 till you reach I, the commit before you made any changes. Say there are two commits after your commit. You could use this to reach commit I.
git reset HEAD~3
And as your files are preserved this may look like
(F) I--Y--C1--C2 ↑ HEAD
Now you could just delete your files from the system and add the files of your collegues (to the index, its already there on FileSystem) and then do a commit. And now the dev line may look like without your changes.
(F1) I--C3 ↑ HEAD
This is not a recommended way. The recommended way to do it is using
git revert HEAD^
Though I have never used it,so to cant tell.
EDIT: Another way of doing it.
Find the “SHA KEY” of the your commit “Y” and commit just before that “I”.
It can be done using
Lets say the for Y key is: 7a2ab465aad23dc66a23ade897deb65a5bf9419d
And for I key is: 906488ac2d5a8468d725351df80e3b0f6338c9be
Make tags for both commits like
git tag Intercommit -a 906488ac2d5a8468d725351df80e3b0f6338c9be git tag YourCommit -a 7a2ab465aad23dc66a23ade897deb65a5bf9419d
Checkout intercommit using
git checkout Intercommit
Then rebase the repo using
git rebase --onto HEAD YourCommit master
Now the line of dev will look like
I--C1--C2 ↑ HEAD
You can find more about rebasing and rewriting one commit on