Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git remove files from only one branch

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

like image 743
krdzo Avatar asked Apr 10 '11 16:04

krdzo


People also ask

How do I remove a file from a specific branch in git?

The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.

How do I remove one file from git?

The git rm command can be used to remove individual files or a collection of files. The primary function of git rm is to remove tracked files from the Git index. Additionally, git rm can be used to remove files from both the staging index and the working directory.


1 Answers

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

like image 51
knittl Avatar answered Sep 27 '22 02:09

knittl