分支交换更新而不合并



我有两个工作分支:masterfeatures。我做了git checkout features,并在我的features分支上工作。我喜欢这些变化,但没有做出任何承诺。

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

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

来自文档:

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

如果您在暂存区中进行了未限制的更改(在分支上时features(涉及在featuresmaster分支之间未修改的文件(甚至可能是文件的一部分——我在这里不确定((即,这些文件在两个分支中都相同(,git checkout只是不涉及更改,并允许您更改分支(否则,git可能会抱怨(。

你现在想做的是:

  1. git checkout features
  2. git commit

最新更新