问题
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