git remove files from only one branch

那年仲夏 提交于 2019-12-05 10:06:50

问题


when I delete files from one branch it deletes from all branches. what can I do?


回答1:


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).

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




回答2:


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.



来源:https://stackoverflow.com/questions/5613235/git-remove-files-from-only-one-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!