如何在切换分支时保留更改而不使用`git stash`

pcww981p  于 11个月前  发布在  Git
关注(0)|答案(1)|浏览(94)

我在分支x上做了一些更改,但我 * 没有暂存或提交 * 任何新的更改,我得到:

% git checkout other/existing/branch
error: Your local changes to the following files would be overwritten by checkout:
        apps/node-be/package.json
Please commit your changes or stash them before you switch branches.
Aborting

字符串
出于某种原因,我的印象是,如果这些变化没有阶段或提交,他们将被移动(我发誓有时会发生这种情况),但我想这显然会导致冲突,所以合并将是必要的。
是否有一个标志来 checkout 一个分支,如果没有冲突,则保留更改?

git checkout --mine other/existing/branch


另一种方法似乎是:

git stash
git checkout other/existing/branch
git stash apply


所以我想,在某种程度上,我会寻找一个单行命令:

git checkout --from-stash other/existing/branch


或什么

tjvv9vkg

tjvv9vkg1#

这可能会在冲突中运行,但您可以使用--merge选项(a.k.a -m)来保留本地更改,即使文件在您切换的分支之间发生了更改。

git checkout --merge other/existing/branch

字符串
或者更现代的

git switch --merge other/existing/branch

相关问题