git - 分支交换更新而不合并
问题描述
我有两个工作分支:master
和features
. 我做了git checkout features
并在我的features
分支上工作。我喜欢这些更改,但没有提交任何内容。
然后我回到我的 master 分支 ( git checkout master
) 并且在执行 agit 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
推荐阅读
- html - 是否有一种无需更改网站代码库的无代码方式将小部件添加到网站?
- google-api - GKE MasterAuth clientCertificate 无权访问集群资源
- flutter - 长按动作栏的后退箭头在颤动中显示“返回”吐司,如何删除?
- python - 是否可以用一个字典理解提取两个值?
- flutter - 在 Dart lang 中创建注解
- node.js - Can't access Ionic from browser while using docker
- django - What is the best way to volume existing database to the container?
- c# - Copy unmanaged DLL from NuGet package to ASP.NET API
- c# - 原始类型或结构无法解析:System.String hook [AfterStep] specflow C#
- python-3.x - Creating time series data from table