'git fetch

编程入门 行业动态 更新时间:2024-10-25 20:21:10
本文介绍了'git fetch -p'是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在删除一个本地分支时,我误会了此命令,

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

本文发布于:2023-08-01 04:20:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1265162.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:git   fetch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!