在一个分支上更改的文件在两个分支上发生变化 [英] File changed on one branch changes on both branches

查看:69
本文介绍了在一个分支上更改的文件在两个分支上发生变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的机器上试验Git。我克隆了一些仓库,并添加了一个新的分支 my_branch



在这个分支中,文件。我没有添加更改,显然没有 commit 它。



然后我再次切换到 master ,并查看了磁盘上的文件。

两个问题:

<1->这是否应该发生?

>

2-这是否意味着作为一般规则,我应该始终添加在切换到分支之前对分支做的任何更改一个不同的分支来做一些不同的工作(即使我不想提交我的更改)?

解决方案

回答1:
是的。就像@bmargulies说的,除非你做了一些事情,否则当你改变分支的时候,git会保留这个改变。



回答2:
是和否。你应该添加并提交它的更改,如果您希望他们在您正在处理的分支上。如果不是,推荐的方法是存储更改,直到您回到您正在处理的分支,然后应用弹出藏匿处。


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. I didn't add the change, and obviously didn't commit it.

I then switched again to master, and looked at the file on the disk. The change appeared there as well.

Two questions:

1- Should this be happening?

2- Does this mean that as a general rule, I should always add any change I did in a branch before switching to a different branch to do some different work (even if I don't want to commit my change yet)?

解决方案

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.

这篇关于在一个分支上更改的文件在两个分支上发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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