gpt4 book ai didi

git - 来自另一个分支的 checkout 文件夹不会删除文件

转载 作者:太空狗 更新时间:2023-10-29 14:02:43 33 4
gpt4 key购买 nike

我正在尝试将一个分支上的整个文件夹的内容移动到不同的分支。所有修改或添加的文件都正确反射(reflect)在新分支中,但删除的文件仍然显示,就好像没有与之相关的更新一样。

当我修改其中一个文件、添加新文件并删除 DEV 分支上 TSTGIT 文件夹中的现有文件之一,然后提交更改、 check out UAT 分支并从 DEV 分支 check out TSTGIT 文件夹时,我希望查看所有 3 个更改,但被删除的文件被完全忽略。

git checkout UAT
git checkout DEV -- TSTGIT
git status

要提交的更改:

    new file:   TSTGIT/addedFile.txt
modified: TSTGIT/modifiedFile.txt

我发现的唯一方法是使用“补丁”参数,它让我也可以选择删除文件,但我想自动执行此操作而无需提供其他信息

git checkout -p DEV -- TSTGIT

请问是否有办法强制包含所有更改?

非常感谢您的帮助;)

最佳答案

默认 git checkout 只在工作目录中添加或修改文件——它从不删除它们。这叫做 overlay mode :

overlay
Only update and add files to the working directory, but don’t delete them, similar to how cp -R would update the contents in the destination directory. This is the default mode in a checkout when checking out files from the index or a tree-ish.

在哪里 <tree-ish> 是指向 tree 的引用对象,通常是提交。

As of Git 2.22 , 你可以通过 --no-overlay git checkout 的选项从工作目录中删除引用树中丢失的任何文件:

When specifying --no-overlay, files that appear in the index and working tree, but not in <tree-ish> are removed, to make them match <tree-ish> exactly.

你的命令应该是:

git checkout --no-overlay DEV -- TSTGIT 

有趣的是,使用 --patch 时能够删除文件的原因选项,是因为它暗示 --no-overlay .

来自documentation :

Note that this option uses the no overlay mode by default, and currently doesn’t support overlay mode.

关于git - 来自另一个分支的 checkout 文件夹不会删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57556378/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com