git,本地分支的变化会影响其他本地分支吗?
git, change on local branch affects other local branches?
我有一个master分支
现在为了测试其他东西,我创建了一个分支 A
我检查分支 A 修改文件,当我再次检查主文件时,更改也在那里。
在其他存储库上我有正确的行为
未提交的更改将从一个分支移动到另一个分支。为了使它们分开,您必须 stash
在移动到另一个分支之前进行这些更改。当你 return 到你的分支时,你可以 apply
那些更改来检索它们。
如下图:
>$ git status
On branch branch_1
Your branch is up-to-date with 'origin/branch_1'.
modified: dir/file.rb
>$ git stash
>$ git checkout <branch_2>
>$ git checkout <branch_1> #after finishing your tasks in branch_2 you can go back to branch_1
>$ git stash apply
现在您将取回之前在 branch_1
中所做的更改
I checkout branch A modify the file and when I checkout master again the changes are there as well.
未提交的更改不属于任何分支。它们仅存在于工作树中(如果添加了它们,则存在于索引中)。
切换分支时最好有一个干净的工作树,以避免工作树中的更改与切换分支之间的差异发生冲突时出现麻烦。
因为分支 A
刚刚创建,您没有在其上提交任何内容,也没有在 master
上提交任何内容,所以分支 A
指向与 [=12= 相同的提交] 并且在 A
和 master
之间切换不需要更改工作树。这就是为什么您可以切换分支而不会发生冲突的原因。
为了将您刚刚所做的更改放入一个分支(假设签出的分支是 A
),您必须将其添加到索引然后提交它们:
git add .
git commit
详细了解 git add
and git commit
。
我有一个master分支
现在为了测试其他东西,我创建了一个分支 A
我检查分支 A 修改文件,当我再次检查主文件时,更改也在那里。
在其他存储库上我有正确的行为
未提交的更改将从一个分支移动到另一个分支。为了使它们分开,您必须 stash
在移动到另一个分支之前进行这些更改。当你 return 到你的分支时,你可以 apply
那些更改来检索它们。
如下图:
>$ git status
On branch branch_1
Your branch is up-to-date with 'origin/branch_1'.
modified: dir/file.rb
>$ git stash
>$ git checkout <branch_2>
>$ git checkout <branch_1> #after finishing your tasks in branch_2 you can go back to branch_1
>$ git stash apply
现在您将取回之前在 branch_1
中所做的更改I checkout branch A modify the file and when I checkout master again the changes are there as well.
未提交的更改不属于任何分支。它们仅存在于工作树中(如果添加了它们,则存在于索引中)。
切换分支时最好有一个干净的工作树,以避免工作树中的更改与切换分支之间的差异发生冲突时出现麻烦。
因为分支 A
刚刚创建,您没有在其上提交任何内容,也没有在 master
上提交任何内容,所以分支 A
指向与 [=12= 相同的提交] 并且在 A
和 master
之间切换不需要更改工作树。这就是为什么您可以切换分支而不会发生冲突的原因。
为了将您刚刚所做的更改放入一个分支(假设签出的分支是 A
),您必须将其添加到索引然后提交它们:
git add .
git commit
详细了解 git add
and git commit
。