git git只从一个分支中删除文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5613235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git remove files from only one branch
提问by krdzo
when I delete files from one branch it deletes from all branches. what can I do?
当我从一个分支删除文件时,它会从所有分支中删除。我能做什么?
回答by knittl
when deleting a file with git and persisting that project state (git commit
) it will only be deleted in that commit and its children (speaking: in that branch). when merging that branch into another branch it might well be possible, that the file is going to be deleted (unless changed in the other branch).
使用 git 删除文件并保留该项目状态 ( git commit
) 时,它只会在该提交及其子项中删除(说:在该分支中)。将该分支合并到另一个分支时,很可能会删除该文件(除非在另一个分支中更改)。
when deleting a file, not committing it and then switching branches, git will apply your current set of changes to the other branch, in your case deleting the file there too. committing the delete should avoid the issue you are seeing
当删除一个文件,而不是提交它然后切换分支时,git 会将您当前的更改集应用到另一个分支,在您的情况下也会删除那里的文件。提交删除应避免您看到的问题
回答by Boris Bucha
No, it is not true. I think your confusion comes from switching between the branches. when you do "git checkout " it preserves your working tree so files you just deleted dont reappear after switching. It is possible to switch to different branch and reset all the changes you have done (you delete files). you can do this by for example writing ""git reset --hard" after switching.
不,这不是真的。我认为您的困惑来自在分支之间切换。当您执行“git checkout”时,它会保留您的工作树,因此您刚删除的文件在切换后不会重新出现。可以切换到不同的分支并重置您所做的所有更改(您删除文件)。例如,您可以通过在切换后编写“”git reset --hard”来实现。