如何从git存储库中删除冲突的引用? [英] How do I remove conflicting reference from git repository?
问题描述
git ls-remote git@github.com: company / project.git master
9547e4ba01d67e1ff3xxxxxd5110eaaf2f48 refs / for / master
06106b7f1005dbb9f1xxxxxxxx456d2be84346c refs / heads / master
如何删除或重命名refs / for / master,以便ls-remote命令只提供一个结果 -
git ls-remote git@github.com:company / project.git master
06106b7f1005dbb9f1xxxxxxxx456d2be84346c refs / heads / master
选项1:删除引用
如果要删除 refs / for / master
引用,只需从远程删除它(使用以下之一):
git push git@github.com:company / project.git:refs / for / master
git push git@github.com:company / project.git --delete for / master
选项2:重命名引用
这是一种可以重命名的方法,但它的工作量要大得多。首先,您需要获取 refs / for / master
引用的对象。我只知道如何编辑你的repo的 .git / config
来获取它。
为了方便起见,假设你添加 git@github.com:company / project.git
作为一个名为 origin
的远程到你本地的repo :
git remote add origin git@github.com:company / project.git
然后让我们说你在本地克隆的<$ c中设置了 fetch
配置$ c> .git / config 文件如下:
[remoteorigin]
url = git@github.com:company / project.git
fetch = refs / for / *:refs / remotes / origin / for / *
然后,一旦你 git fetch origin
,你可以重新命名引用,然后再次推送它尽管如此,你仍然需要删除旧的引用):
git push origin:refs / for / master origin / for / master:for / master
:refs / for / master
删除旧引用, origin / for / master:for / master 将该引用的旧副本作为新的远程引用推入 for / master
。
您可以阅读更多关于章节中的 fetch
远程回购的refspec配置9.5 Git内部 - FREE 的Refspec 在线专业版Git书。
I currently have 2 symbolic references with master in the name as below
git ls-remote git@github.com:company/project.git master
9547e4ba01d67e1ff3xxxxxd5110eaaf2f48 refs/for/master
06106b7f1005dbb9f1xxxxxxxx456d2be84346c refs/heads/master
How do I remove or rename the refs/for/master so the ls-remote command only gives one result like so -
git ls-remote git@github.com:company/project.git master
06106b7f1005dbb9f1xxxxxxxx456d2be84346c refs/heads/master
Option 1: Deleting the Reference
If you want to remove the refs/for/master
reference, just delete it from the remote (using one of the following):
git push git@github.com:company/project.git :refs/for/master
git push git@github.com:company/project.git --delete for/master
Option 2: Renaming the Reference
This is one way you can rename it, though it's significantly more work. First, you'll need to fetch the object that refs/for/master
refers to. Only way I know how is to edit your repo's .git/config
to fetch it.
For convenience, let's say that you add git@github.com:company/project.git
as a remote called origin
to your local repo:
git remote add origin git@github.com:company/project.git
Then let's also say that you set up your fetch
configuration in your local clone's .git/config
file to be the following:
[remote "origin"]
url = git@github.com:company/project.git
fetch = refs/for/*:refs/remotes/origin/for/*
Then once you git fetch origin
, you can rename the reference to something else and push it again (you'll still need to delete the old reference though):
git push origin :refs/for/master origin/for/master:for/master
:refs/for/master
deletes the old reference, and origin/for/master:for/master
pushes the old copy of that reference as a new remote reference for/master
.
You can read more about fetch
refspec configuration for remote repos in chapter 9.5 Git Internals - The Refspec of the FREE online Pro Git book.
这篇关于如何从git存储库中删除冲突的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!