How can I fix a reverted git commit?

I've committed a bunch of changes to a repository, and they were reverted by someone else (they compile on windows but not on linux). I think that the changes are still in the history, but how can I get those changes back, fix them, and then resubmit?


Have you tried reverting the revert?

They reverted your commit using

git revert <your commit id>

The revert itself is a commit and has its own commit id. So now you need to do

git revert <the commit id of his revert-commit>

You can try reverting the reverts, using git revert. You can also restore the files from your commit using git checkout. Or you can use git cherry-pick -n to re-apply them and change them. You can create a new branch from your commit where you apply the changes using git branch. The possibilities are (almost) endless. :)


The other answers here address how to revert or cherry-pick your commits, but it sounds from the question as if you also need to know how to find your commits, so here's some guidance on that.

If you just run git log you should see a list of the commits in the history of your current branch, starting with the most recent. Each commit has an identifier technically known as the object name (or "SHA1sum of the commit") that looks like this:

commit d2d434beeb03e4ee648ca7ca2a1ea1ed09077306

... followed by the author name, date and a summary of the changes that were introduced by that commit. When you're specifying the object name for git revert or git cherry-pick you can give it d2d434beeb03e4ee648ca7ca2a1ea1ed09077306 or just enough characters from the beginning of the object name to be unambiguous (e.g. d2d434bee)

git log has many options that can help you track down your commits, like --before, -S, etc. but in this case you particularly might need --author=MyLastName.

A graphical git tool that can present the history nicely to you and is available on every platform is gitk --all. If you click on a commit that you'd like to revert, you can copy-and-paste its object name from the "SHA1 ID" field in the middle of the window.