删除分支中的目录会导致在交换机上删除master中的目录吗? [英] Deleting directory in branch causes directory in master to be deleted on switch?
问题描述
在我的git repo master分支中,我有工作目录/tmp/repo_name/secret_code.如果我切换到名为test的新分支,然后 rm -rf secret_code
..当我改回master时,也会从那里删除secret_code目录.
In my git repo master branch i have working dir /tmp/repo_name/secret_code. If i switch to new branch called test and then rm -rf secret_code
.. when i change back to master it deletes the secret_code directory from there as well.
我认为,如果我在git分支上进行更改,则它充当更改的容器,因此在更改到另一个分支时,工作目录将反映该分支的状态.
I thought if i make changes on a git branch that it acts as a container for changes so on changing to another branch the working dir will reflect that branches state.
为什么当我从分支中删除文件时,那些动作会反映在我的主分支上?
Why when i remove files from a branch are those actions reflected on my master branch ?
谢谢.
推荐答案
为什么当我从分支中删除文件时,那些动作会反映在我的主分支上?
Why when i remove files from a branch are those actions reflected on my master branch ?
因为您修改了工作树:当您切换回 master
时,如果 master
没有对 secret_code
进行修改,将保持工作树不变,并且 git status
将反映该文件夹的删除.
Because you modified the working tree: when you switch back to master
, if master
didn't have modifications done on secret_code
, it will keep the working tree as is, and the git status
will reflect the deletion of that folder.
这只会删除 test
分支中的 secret_code
:
git checkout test
git rm -r secret_code
git add -u .
git commit -m "removes secret_code in test"
然后:
git checkout master
您将仍然在该 master
分支中看到 secret_code
.
这篇关于删除分支中的目录会导致在交换机上删除master中的目录吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!