我刚刚注意到,在删除它之后,我仍然可以切换回一个分支。下面是我的一个具体例子:
git switch master
git branch -d AB-10/add_flights
...
// deleting also the remote branch on GitHub
git switch AB-10/add_flights
// I see the branch again怎么会这样?
发布于 2022-08-08 09:00:56
原因很简单:您只在本地删除了它。
手册页报告:
Optionally a new branch could be created with either -c, -C, automatically from a remote branch of same name (see --guess), or detach the working tree from any branch with
--detach, along with switching.由于它仍然存在于远程,所以GIT可以再次切换到它。
通过git push --delete origin <branch-name>删除它,然后再试着检查它.
发布于 2022-08-08 09:56:28
git switch是一个新引入的命令,用于从git checkout中承担一些负担。
根据git结帐的手册,
git结帐
要准备工作,可以通过更新索引和工作树中的文件,并将头指向分支来切换到它。保存对工作树中文件的本地修改,以便将它们提交给。 如果没有找到,但确实在一个具有匹配名称的远程(调用它)中存在一个跟踪分支,并且没有指定--无猜测,则视为等效于
$ git checkout -b <branch> --track <remote>/<branch>因此,在删除分支并运行git checkout <branch>之后,将再次从<remote>/<branch>创建分支。
它也适用于git switch。
发布于 2022-08-08 08:59:13
一个好的做法是在删除远程和本地分支之后进行修剪,您可以这样做。
git fetch --prune这将删除删除远程分支的所有本地副本。
来自man页面:
-p, --prune
Before fetching, remove any remote-tracking references that no longer exist on the remote.
Tags are not subject to pruning if they are fetched only because of the default tag
auto-following or due to a --tags option. However, if tags are fetched due to an explicit
refspec (either on the command line or in the remote configuration, for example if the
remote was cloned with the --mirror option), then they are also subject to pruning.
Supplying --prune-tags is a shorthand for providing the tag refspec.https://stackoverflow.com/questions/73275144
复制相似问题