GIT undo branch -D

fre*_*sko 2 git

After merged my changes on the main remote branch, I wanted to remove the name of my branch and leave the branch where it is. Only delete its name (in my team they don't like branches with names, unless they are releases).

So I did the following:

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
Run Code Online (Sandbox Code Playgroud)

But the whole branch was removed, and also on the header the changes disappeared. Is possible to undo that "branch -D" command?

Else I will must redo the work and wait for a pull-request. I also don't know why the message that the branch was not fully merget, it seemed to me that all the changes where on the remote branch.

---edit--- I solved by re-doing the merge, (now it's difficult to explain by word how the tree looked like). After that, I had another problem, because when i wanted to assign a tag to a branchA, this tag was assigned to branchB. My console told me that i am on branchA, but GIT pointed to branchB. So i did:

$ 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
Run Code Online (Sandbox Code Playgroud)

To solve, i did:

git pull origin branchA
Run Code Online (Sandbox Code Playgroud)

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

Jes*_*man 6

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

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

git checkout -b <branch> <sha>