git,本地分支上的更改会影响其他本地分支吗? [英] git, change on local branch affects other local branches?

查看:685
本文介绍了git,本地分支上的更改会影响其他本地分支吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主分支

现在为了进行其他测试,我创建了一个分支A

now for some testing other things I made a branch A

我检出分支A修改文件,当我再次检出master时,更改也在那里.

I checkout branch A modify the file and when I checkout master again the changes are there as well.

在其他存储库中,我的行为正确

On other repositories I have the right behaviour

推荐答案

未提交的更改将从一个分支移动到另一个分支.为了使它们分开,必须将这些更改stash移至另一个分支.返回分支时,可以apply进行更改以检索它们.

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.

如下所示:

>$ 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中所做的更改

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

这篇关于git,本地分支上的更改会影响其他本地分支吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆