2014-04-02 30 views
2

我最近重命名一个新的别名的远程和旧的别名(及其所有提交直到重命名)仍然可见的日志,因此gitk。运行旧的远程别名在git日志和gitk中仍然可见,如何删除?

$ git remote show old-alias 

显然返回:

fatal: 'old-alias' does not appear to be a git repository 

这是烦了。我如何干净地删除这些引用?是否可以手动删除

.git/logs/refs/remotes/old-alias/ 
.git/refs/remotes/old-alias/ 

目录?

编辑:

这里是git remote -v输出:

origin [email protected]:my-user/our-repo (fetch) 
origin [email protected]:my-user/our-repo (push) 
upstream  [email protected]:upstream-user/our-repo (fetch) 
upstream  [email protected]:upstream-user/our-repo (push) 

这里是git log --oneline --graph --decorate输出:

* 692d53f (HEAD, origin/somebranch, somebranch) Commit message                                 
* 9a4e794 Commit message                                      
* 419376b Commit message 
* 9a945bd (origin/someotherbranch, someotherbranch) Commit message 
* 9a0fe3b Commit message 
* 021d553 Commit message 
* fa60dba Commit message 
* 2d52d72 Commit message 
* c59307f Commit message 
* b89ae1c Commit message 
* 063030c Commit message 
* 97b8c77 Commit message 
* ec65002 Commit message 
* 38d7bb8 Commit message 
* 36856fc Commit message 
* 13b5065 Commit message 
* 66e7dae (upstream/master, origin/master, old-alias/master, master) Commit message 
|\ 
| * caf7e86 Commit message 
| * a0c5abe Commit message 
| * 9d1a735 Commit message 
| * 4e7770d Commit message 
| * cd3dd89 Commit message 
* | 3037432 Merge pull request message 
|\ \ 
| |/ 
| * 12b4a01 Commit message 
| * be41159 Commit message 
|/ 
* 8210859 Commit message 
* 6b2090e Commit message 
* 4b069f3 Commit message 
* 1ef939c Merge pull request message 
|\ 
| * fc559bb Commit message 
|/ 
* 6fab424 Commit message 
* ce10b38 Commit message 
* 345128e Commit message 

old-alias改为origin通过git remote rename old-alias origin各地提交2d52d72

+2

请参见http://计算器。com/questions/3184555/cleaning-up-old-remote-git-branches – bitoiu

+1

我不明白这会怎样帮助我的案例,它与远程分支有关。我的问题是一个完整的遥控器。 –

+0

在'.git'下删除文件通常不是一个好主意,除非你真的知道你在做什么。 'git remote -v'的输出是什么?你的意思是说旧的别名仍然显示在日志中?我们能看到吗? git log --oneline --graph --decorate的输出是什么? –

回答

2

这里的问题有一个类似的问题:Why is old name of git remote sill in .git/refs/remotes?。根据那里的建议,我删除了

.git/logs/refs/remotes/old-alias/ 
.git/refs/remotes/old-alias/ 

手动目录。有残留在日志和.git/logs/HEAD.git/logs/refs/heads/someotherbranch

./logs/HEAD:14:6d8019... Ayberk Özgür <[email protected]> 1394819391 +0100 pull old-alias someotherbranch: Fast-forward 
./logs/refs/heads/android:13:6d8019... Ayberk Özgür <[email protected]> 1394819391 +0100  pull old-alias someotherbranch: Fast-forward 

我完全不知道如果那剩下的old-alias的唯一痕迹是否可能是有害的。但是,到目前为止我还没有遇到任何问题。

0

首先,我结束了:

export REMOTE_NAME="old-alias" # insert your remote name 
for branch in $(git branch -a | grep -o "${REMOTE_NAME}/.*") ; do 
    git branch -r -d $branch 
done 

我有一个非常类似的问题,但即使硬拼从我的.git目录删除内容 - 可能不这样做! - 我仍然有远程引用。

对我来说,诀窍在于使用-r选项来删除git分支:012ey,正如bitoiu(在引用的答案中)所建议的那样。

我将此与git br -a一起使用,因为我有~20个孤立的远程分支,我想遍历它们以将它们全部删除。

我希望读者有git grep有-o选项只返回匹配的子字符串。如果没有,请使用您选择的工具修剪前导remotes/,例如我在QNX上使用的| sed -e 's/^remotes.//'(尽管我没有QNX上的git)。

最后,如果你喜欢一个衬垫,这是值得学习的sh/bash中的一环行语法:for branch in $(git branch -a | grep -o "old-alias/.*") ; do git branch -r -d $branch ; done