Reputation: 22519
This might be a dumb question but I rather be safe then messing everything up.
I made two bad commits...I deleted a folder in one commit. In the next commit, I recreated the folder. After I made those commits, my teammates have made commits to the repo, but their commits are independent of my commits. (I have my own folder and I made changes to it).
How can I undo my two commits without affecting the commits made by my teammates?
Lets say the commit hashes are AAA111 for the first commit and BBB222 for the second commit.
Thanks!
Upvotes: 2
Views: 93
Reputation: 26505
If your commits are either not yet pushed or only pushed to a private branch (i.e. no one else is working on that branch) you can use git rebase -i AAA111^
and delete those commits. In this case your bad commits did never happen. :)
If you already pushed your commits you cannot simply remove those commits. You have to add new commits to undo the changes made by the original commits. Use git revert AAA111 BBB222
for that.
Upvotes: 1
Reputation: 43690
If your commits are pushed, you can run git revert
on each of the commits and undo them. Or when you are pulling in the changes, you will end up with a merge conflict and the changes will be resolved.
If your changes are only on your local branch, you can git reset --hard <sha of commit before your commits>
WARNING: This will delete all your changes. This will make it so that you commits did not happen.
If your changes are only on your local branch and you have other commits that you want to keep, you can do git rebase -i <sha of commit before your changes>
, this will bring up an editor listing all the commits that you have. Delete the two commits that you no longer want, save the file. This will remove the commits from your history and save the other commits that you have.
Upvotes: 1