【问题标题】:Old remote alias still visible in git logs and gitk, how to delete?旧的远程别名在 git 日志和 gitk 中仍然可见,如何删除?
【发布时间】:2014-05-13 09:32:14
【问题描述】:

我最近将远程重命名为新别名,而旧别名(以及在重命名之前的所有提交)在日志中仍然可见,因此在 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  git@github.com:my-user/our-repo (fetch)
origin  git@github.com:my-user/our-repo (push)
upstream        git@github.com:upstream-user/our-repo (fetch)
upstream        git@github.com: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 在提交 2d52d72 周围通过 git remote rename old-alias origin 更改为 origin

【问题讨论】:

  • 我看不出这对我的案子有什么帮助,它与远程分支有关。我的问题是一个完整的残留遥控器。
  • 除非您真的知道自己在做什么,否则只删除.git 下的文件通常不是一个好主意。 git remote -v 的输出是什么?你是什​​么意思旧别名仍然出现在日志中?我们能看到吗? git log --oneline --graph --decorate 的输出是什么?
  • 我添加了您要求的信息。

标签: git git-remote


【解决方案1】:

这里的问题也有类似的问题: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 <ayberk.ozgur@email.com> 1394819391 +0100   pull old-alias someotherbranch: Fast-forward
./logs/refs/heads/android:13:6d8019... Ayberk Özgür <ayberk.ozgur@email.com> 1394819391 +0100     pull old-alias someotherbranch: Fast-forward

我不知道这些是否是old-alias 留下的唯一痕迹,或者它们是否有害。但是,到目前为止,我还没有遇到任何问题。

【讨论】:

    【解决方案2】:

    首先,我得到了什么:

    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 分支:git branch -r -d,正如 bitoiu 所建议的那样(在引用的答案中)。

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

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

    最后,如果你更喜欢单行,值得学习 sh/bash for loop 单行语法:for branch in $(git branch -a | grep -o "old-alias/.*") ; do git branch -r -d $branch ; done

    【讨论】:

      猜你喜欢
      • 2020-04-03
      • 1970-01-01
      • 1970-01-01
      • 2019-05-18
      • 2013-07-02
      • 2016-08-06
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      相关资源
      最近更新 更多