I work in many branches and have pulled a file from one branch ( branchA
) to the current one ( branchB
).
I used git checkout file.name
I would like to remove file.name
from branchB without modifying branchA
. Will git rm -f file.name
remove the file from just branchB
or will it remove it from branchA as well?
Any git operation you do will be for the current checked out branch itself.
So git add, rm , commit will only be effective for the currently checked out branch itself.
just make sure you do not cherry-pick the commit into another branch. In that case you may lose it :) but don't worry you can always get it back by reverting to older commit. So chill, git is your best friend
It will only be removed from the current branch. If you check out another branch, the file will be present again.
Strictly speaking, running
git rm -f file.name
does not affect any branch, yet. This command merely
file.name
(in other words, it writes, in the index, that file.name
should no longer be tracked.) Then, when you create a commit, the tree object of the current branch's new tip will no longer reference file.name
.
And because staging and committing only affect the current branch, the other branches (if any) will not be affected by this removal. If you later check another branch (to which file.name
was committed), file.name
will be checked out to your working tree.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.