Switch Git branch without files checkout

前端 未结 11 1442
佛祖请我去吃肉
佛祖请我去吃肉 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

    say you want to be in branch A, but with the files from branch B

    find the current commit ref of branch A with git log, e.g. "99ce9a2",

    git checkout A
    git reset --hard B
    git reset 99ce9a2
    

    you should now be on branch A, with a folder structure corresponding to B, which show up as unstaged changes (A history has not changed).

提交回复
热议问题