首页 > 解决方案 > 分支交换更新而不合并

问题描述

我有两个工作分支:masterfeatures. 我做了git checkout features并在我的features分支上工作。我喜欢这些更改,但没有提交任何内容。

然后我回到我的 master 分支 ( git checkout master) 并且在执行 agit status时,我在分支的暂存区域中所做的所有更改features也在我的master分支中。当我从master分支运行我的应用程序并且更改就在那里时,这一点得到了进一步证明。

问题是分支机构如何在没有合并的情况下交换信息?首先使用分支的目的是如果我搞砸了,我可以简单地删除分支,不用担心。发生的情况是,我在features分支上所做的更改会自动转移到master分支上,而无需我手动执行。

标签: gitgit-checkout

解决方案


从文档:

git checkout <branch>

To prepare for working on <branch>, switch to it by updating the index and the files 
in the working tree, and by pointing HEAD at the branch. Local modifications to the 
files in the working tree are kept, so that they can be committed to the <branch>.

所以你去。您的本地修改被保留,并移至新分支,因为不需要合并。

如果您的更改发生冲突并需要合并,这是不可能的。在这种情况下,您会收到一条消息:

error: Your local changes to the following files would be overwritten by checkout:
        <your files here>
Please, commit your changes or stash them before you can switch branches.
Aborting

推荐阅读