首页 文章

如何使用提交sha在github上创建新分支

提问于
浏览
2

您好我试图解决我的问题,但没有成功 . 我在GitHub上创建了一个分支并在那之后做了一个提交,之后我删除了一个分支,但我知道我的提交 . 我尝试使用我的sha创建新的分支,但我不能 . 我尝试做以下事情

git checkout && git branch - b SPP-69 47127ee98d8247d67f0f2baf3ae316444bc1ea9e
# and got 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.

我没有本地的reflog .

2 回答

  • -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 which you are searching for its parent
    treeish=<your tree sha-1>
    
    # 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
    
  • 0

    我可以创建一个分支但我不能用我没有分支的提交来做

    这意味着它不再被任何分支或标记引用,因此默认情况下不会被提取,即使是 git fetch --all .

    尝试并单击New Pull请求:这应该创建一个PR branch that you can then fetch locally .

    git fetch origin pull/ID/head:BRANCHNAME
    git checkout BRANCHNAME
    

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

相关问题