How can I fix a reverted git commit?

后端 未结 4 1934
半阙折子戏
半阙折子戏 2021-02-03 18:19

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

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-03 18:41

    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.

提交回复
热议问题