Switch Git branch without files checkout

前端 未结 11 1458
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 15:36

Is it possible in Git to switch to another branch without checking out all files?

After switching branch I need to delete all files, regenerate them, commit and swit

11条回答
  •  日久生厌
    2020-11-29 16:12

    Using basic git commands only:

    This answer is a bit longer than that of Charles, but it consists solely of basic git commands that I can understand and thus remember, eliminating the need to keep looking it up.

    Mark your current location (commit first if needed):

    git checkout -b temp
    

    Reset (moves) the marker to the other branch without changing working dir:

    git reset 
    

    now temp and other branch point to the same commit, and your working dir is untouched.

    git checkout 
    

    since your HEAD is already pointing to the same commit, working dir is not touched

    git branch -d temp
    

    Note that these commands are also readily available from any graphical client.

提交回复
热议问题