git, change on local branch affects other local branches?

前端 未结 2 1522
花落未央
花落未央 2021-01-31 19:41

I have a master branch

now for some testing other things I made a branch A

I checkout branch A modify the file and when I checkout master again the changes are t

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 20:08

    Uncommitted changes will move from one branch to other. To keep them separated, you must stash those changes before moving to another branch. When you return to your branch, you can apply those changes to retrieve them.

    As seen below:

    >$ git status
    On branch branch_1
    Your branch is up-to-date with 'origin/branch_1'.
    
    modified:   dir/file.rb 
    >$ git stash
    >$ git checkout 
    
    >$ git checkout  #after finishing your tasks in branch_2 you can go back to branch_1
    >$ git stash apply
    

    Now you will get back the changes you have done earlier in branch_1

提交回复
热议问题