问题描述
在删除一个本地分支时,我误会了此命令,
I had run this command with misunderstandings while I was deleting my one local branch,
git branch -D branch-name
git fetch -p
但我已经看到它们是列出的要删除的分支名称的列表.
but I have seen their is a list of branch names that are showing to be deleted.
我很害怕看到已删除分支列表的列表,以为是我执行了错误的命令,并意外删除了所有分支!
I was afraid to see the list of deleted branches list, and thinking might be I had executed wrong command, and accidentally deleted all the branches!!
此命令(git fetch -p
)的含义是什么.任何的想法?
What does mean of this command (git fetch -p
). Any idea?
推荐答案
获取远程存储库时,说"origin",您将获得该远程存储库中存在的每个分支的远程分支. .这些分支在本地存储为<remote>/<branch>
.
When you fetch a remote repository, say "origin", you will get remote branches for each branch that exists on that remote repository. Those branches are locally stored as <remote>/<branch>
.
因此,假设原点具有分支master
,featureX
和featureY
.然后,在获取本地存储库中的以下远程分支"之后:origin/master
,origin/featureX
和origin/featureY
.
So assume origin has branches master
, featureX
and featureY
. Then after fetching the following "remote branches" exist in your local repository: origin/master
, origin/featureX
and origin/featureY
.
现在,假设其他人将featureX
合并到master中,并从远程存储库中删除了功能分支.然后原点只有两个分支master
和featureY
.
Now, imagine someone else merges featureX
into master and removes the feature branch from the remote repository. Then origin only has two branches master
and featureY
.
但是,当您进行提取时,三个远程分支将仍然存在,包括在远程存储库中删除的三个分支.这是为了防止您意外丢失分支(想象有人不小心从远程删除了分支,那么从分支中获取数据的每个人也会丢失该分支,从而使其难以恢复).
However, when you fetch, the three remote branches will all still exist, including the one that was deleted in the remote repository. This is to prevent you from accidentally losing the branch (imagine someone accidentally removed the branch from the remote, then everyone who fetched from it would also lose it, making it hard to restore it).
相反,您将需要告诉fetch命令对远程分支上不再存在的任何分支进行修剪.因此,通过执行git fetch --prune origin
或git fetch -p
,远程分支origin/featureX
也将被删除.
Instead, you will need to tell the fetch command to prune any branches that no longer exist on the remote branch. So by executing git fetch --prune origin
or git fetch -p
the remote branch origin/featureX
will be removed too.
顺便说一句.如果要从远程存储库中删除分支,则必须将空"分支推入该分支,例如git push origin :branchname
将在本地和远程本身上删除远程分支origin/branchname
.
Btw. if you want to remove a branch from a remote repository, you will have to push an "empty" branch to it, e.g. git push origin :branchname
will remove the remote branch origin/branchname
both locally and on the remote itself.
这篇关于'git fetch -p'是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!