从另一个分支的Checkout文件夹不会删除文件 [英] Checkout folder from another branch doesnt delete files

查看:117
本文介绍了从另一个分支的Checkout文件夹不会删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个分支上整个文件夹的内容移到另一个分支.所有修改或添加的文件都正确地反映在新分支中,但是删除的文件仍然显示,好像没有与之相关的更新.

I am trying to move the content of entire folder on one branch into different branch. All the files that were modified or added are correctly reflected in the new branch however the files that were deleted are still displayed as if there was no update related to them.

当我修改其中一个文件时,在DEV分支的TSTGIT文件夹中添加一个新文件并删除其中一个现有文件,然后提交更改,从DEV分支中检出UAT分支并检出TSTGIT文件夹,我希望查看所有3个更改,但是已删除的文件将被完全忽略.

When i modify one of the files, add a new file and delete one of the existing files in TSTGIT folder on DEV branch and then commit the changes, checkout the UAT branch and checkout TSTGIT folder from DEV branch, I would expect to see all 3 changes, but the file that was deleted is completely ignored.

git checkout UAT
git checkout DEV -- TSTGIT
git status

要提交的更改:

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

我发现的唯一方法是使用'patch'参数,在该参数中我还可以选择删除文件,但是我想自动执行此操作而无需提供其他信息

The only way i found is to use 'patch' argument where it let me choose also to delete the file but i would like to do this automatically without the need to provide another information

git checkout -p DEV -- TSTGIT

请问您是否有办法强制所有更改都包括在内?

Pls do you know if there is a way how to force all the changes to be included?

非常感谢您的帮助;)

推荐答案

git checkout DEV -- TSTGIT的问题在于该命令复制文件,而不应用更改;并且复制的文件当然不包括已删除的文件.

The problem with git checkout DEV -- TSTGIT is that the command copies files, not applies changes; and copied files certainly doesn't include deleted files.

如果您要同步目录-即使其成为另一个分支的目录的精确副本,则可以先删除该目录,然后再从另一个分支检出该目录:

If you want to synchronize the directory — i.e. make it an exact copy of the directory from the other branch, you can remove the directory before checking it out from the other branch:

git checkout UAT
rm -rf TSTGIT
git checkout DEV -- TSTGIT

该方法的问题在于,它会删除分支DEV中已存在但在UAT中从未存在(并且未被删除)的文件.

The problem with the approach is that it removes files that existed in branch DEV but never existed (and were not deleted) in UAT.

如果要应用更改而不删除目录,则唯一的方法是类似于git checkout -p的方法.可能是git cherry-pick --no-commit;但是之后,您必须还原除TSTGIT以外的所有目录.

If you want to apply changes without deleting the directory an approach similar to git checkout -p is the only way. Could be git cherry-pick --no-commit; but after that you have to restore all directories except TSTGIT.

这篇关于从另一个分支的Checkout文件夹不会删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆