Git checkout does not change anything

前端 未结 4 542
暗喜
暗喜 2020-12-30 18:47

I really like git. At least, I like the idea of git. Being able to checkout my master project as a separate branch where I can change whatever I want without risk of screw

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-30 18:52

    I like to explain git in common language. Answer: its because of the assumption that changing branches (checkout) will get you to another "workspace". Git doesn't do that (altough it feels more natural, and many have this misunderstanding).

    Instead, branches are like tags, so to speak. So you can dance around branches, do some work, modify things, dance around again, and then commit. Then, the commit will be at the last branch you went to! The checkout only changes the "tag"/branch you'll use, period.

    UPDATE after Martas's comment

    This applies to when your branch and your master are synced (regarding tracked files), or with untracked files. If in fact they are in different states, when you checkout then files and folders will actually disapear and reappear. If you have changes tracked but not commited, then git will actually abort checking out, and you have to either commit or stash them.

提交回复
热议问题