gpt4 book ai didi

GIT撤消分支-D

转载 作者:行者123 更新时间:2023-12-05 09:18:30 26 4
gpt4 key购买 nike

在主远程分支上 merge 我的更改后,我想删除分支的名称并将分支保留在原处。只删除它的名字(在我的团队中,他们不喜欢有名字的分支,除非它们是发布版)。

所以我做了以下事情:

git branch -d branch_2b_deleted
error: The branch 'branch_2b_deleted' is not fully merged.
If you are sure you want to delete it, run 'git branch -D branch_2b_deleted'
git branch -D branch_deleted
git push origin :remoteHead

但是整个分支都被删除了,而且标题上的更改也消失了。是否可以撤消该“branch -D”命令?

否则我将必须重做工作并等待 pull-request。我也不知道为什么分支没有完全 merge 的消息,在我看来所有的更改都在远程分支上。

---编辑---我通过重新进行 merge 来解决,(现在很难用文字来解释树的样子)。之后,我又遇到了一个问题,因为当我想给一个branchA分配一个标签时,这个标签被分配给了branchB。我的控制台告诉我我在 branchA,但 GIT 指向 branchB。所以我做了:

$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=origin/<branch> branchA

为了解决,我做了:

git pull origin branchA

这就完成了工作。我不在 branchA 上,即使在控制台上写着我在 branchA 上(之后:git checkout branchA)。我认为系统应该在这种情况下提供建议,而不是告诉我“只是”在 branchA 上......

最佳答案

是的,git 中有一个名为 git reflog 的实用程序,它会记录您的所有更改。如果您想恢复该分支,请执行以下操作:

执行 git reflog 并在已删除分支的顶端找到提交的 SHA1,然后就

git checkout -b <branch> <sha>

关于GIT撤消分支-D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44242231/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com