File changed on one branch changes on both branches

后端 未结 2 1188
广开言路
广开言路 2021-01-15 11:44

I\'m experimenting with Git on my machine. I cloned some repository and added a new branch my_branch.

In this branch, I edited a row in one source file.

相关标签:
2条回答
  • 2021-01-15 12:02

    Your change is on no branches. If you edit a file, and don't do 'git add', let alone 'git commit', your change will just sit there unless you do something to get rid of it, like git reset --hard HEAD or git checkout PATH. If you went and made a clone of your repo you'd see that your change was not in it. If you used git log you'd see no sign of it.

    0 讨论(0)
  • 2021-01-15 12:06

    Answer to 1: Yes. Like @bmargulies said, unless you do something about it, git keeps the change while you switch branches

    Answer to 2: Yes and No. You should add and commit it the changes if you want them on the branch you were working on. If not, the recommended method is to stash the changes, until you come back to the branch you were working on, and then apply or pop the stash.

    0 讨论(0)
提交回复
热议问题