Temporarily switch working copy to a specific Git commit

前端 未结 3 1984
慢半拍i
慢半拍i 2020-12-22 14:58

How to switch to specific Git commit without losing all the commits made after it?

I want that local files will be changed, but commits\' database w

3条回答
  •  臣服心动
    2020-12-22 15:35

    In addition to the other answers here showing you how to git checkout it's worth knowing you can switch back to where you were using:

    git checkout @{-1}
    

    This is often more convenient than:

    git checkout what-was-that-original-branch-called-again-question-mark
    

    As you might anticipate, git checkout @{-2} will take you back to the branch you were at two git checkouts ago, and similarly for other numbers. If you can remember where you were for bigger numbers, you should get some kind of medal for that.


    Sadly for productivity, git checkout @{1} does not take you to the branch you will be on in future, which is a shame.

提交回复
热议问题