如何使用提交的SHA-1哈希值在GitHub上创建新分支。

4

我尝试解决我的问题,但是没有成功。

我在GitHub上创建了一个分支,并在那里进行了一次提交。之后,我删除了一个分支,但我知道SHA-1哈希值的提交。我尝试使用我的SHA-1哈希值创建一个新分支,但是失败了。

我尝试做以下事情:

git checkout && git branch - b SPP-69 47127ee98d8247d67f0f2baf3ae316444bc1ea9e
# And got a reference is not a tree 47127ee98d8247d67f0f2baf3ae316444bc1ea9e

我尝试做以下事情:

git checkout && git branch - b SPP-69 47127ee98d
# And got 47127ee98d is not a commit and a branch SPP-69 could not be created from it.

Enter image description here

Enter image description here

我没有任何本地的reflog记录。


你本地有那个提交吗? - iBug
2个回答

0
我可以创建一个分支,但是我不能使用没有分支的提交来创建它。
这意味着它不再被任何分支或标签引用,因此默认情况下甚至不会被git fetch --all获取。
尝试点击“新拉取请求”:这应该会创建一个PR分支,然后您可以在本地获取
git fetch origin pull/ID/head:BRANCHNAME
git checkout BRANCHNAME

BRANCHNAME替换为您想要创建的分支名称。


-1

看起来你的机器上没有这个提交。

# Grab the content from the server
git fetch --all --prune

# Now checkout the desired commit
git checkout -b <branch name> <SHA-1>

我们如何找到包含特定tee对象的提交?

您需要找到提交本身,然后检出它。

检查您的日志以查找该提交,然后像您之前那样checkout -b <SHA-1>

如果无法通过Github网页界面找到,请使用此脚本:

#! /bin/sh

# The tee SHA-1 hash value which you are searching for its parent
treeish=<your tree SHA-1 hash value>

# The name of the branch to search in
branch=<branch names>

# Loop over all the commits in the given branch
git rev-list $branch |

    # Search the commits
    while read commit_id; do
        if git ls-tree -d -r --full-tree $sha_id | grep $branch;
           then echo " -- found at $commit_id"
        fi
    done

我认为47127ee是最后一张图片中显示的提交SHA(其父提交为fae7c8c)。 - iBug
不是提交,而是树。 - CodeWizard
谢谢,但是在我执行了 git checkout && git branch - b SPP-69 47127ee 后,我得到了相同的错误:致命错误,47127ee 不是一个提交和分支 SPP-69 无法从中创建。 - Mila Bogomolova
@CodeWizard,也许可以用图片来说明我的立场? - iBug
根据您提供的图片更新了答案。 - CodeWizard
显示剩余6条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接