分支在不合并的情况下交换更新

Branches exchanging updates without merge

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

然后我回到我的 master b运行ch (git checkout master) 并在执行 git status 后,我在 features b运行ch 也在我的 master b运行ch 里。当我 运行 我的应用程序来自 master b运行ch 并且更改在那里时,这进一步证明了这一点。

问题是 b运行ches 如何在没有合并的情况下交换信息?首先使用 b运行ch 的目的是如果我搞砸了,我可以简单地删除 b运行ch,不用担心。发生的事情是,我在 features b运行ch 上所做的更改会自动 t运行sferred 到 master b运行ch,而无需我手动这样做.

如果您在临时区域中进行了未提交的更改(在分支上时 features) 涉及在 featuresmaster 分支之间未修改的文件(或者甚至可能是文件的一部分 - 我在这里不确定)(即这些文件在两个分支中都是相同的)分支),git checkout 根本不触及更改并让您更改分支(否则,git 可能会抱怨)。

你现在要做的是:

  1. git checkout features
  2. git commit

来自文档:

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