Modified files in a git branch are spilling over into another branch

后端 未结 5 1868
后悔当初
后悔当初 2020-11-22 09:01

I am working on a git repository with a master branch and another topic branch. I have switched to topic branch and modified a file. Now, if I switched to master branch that

5条回答
  •  一整个雨季
    2020-11-22 09:27

    • It is not like git branches are dependent on each other but also they do not have a complete code base separately for each branch either.
    • For each commit, Git stores an object that contains a pointer to the changes. So each branch points to its own latest commit and HEAD points to the branch currently you are in.
    • When you switch the branch, the HEAD pointer points to that particular commit of the branch. So if there are modified files, the default behavior is to copy over them.

    You can do the following things to overcome this issue.

    1. Use -f option to ignore the changes.

    If you want to save the changes:

    1. Commit the changes locally in the same branch and then switch the branch.
    2. Use git stash, switch the branch, do your work, switch back to the original branch and do git stash apply.

提交回复
热议问题