【问题标题】:Cygwin git not picking up aliasesCygwin git没有选择别名
【发布时间】:2023-03-20 05:20:02
【问题描述】:

我正在使用 Cygwin 和默认附带的 git (v1.7.9) (/usr/bin/git)。我还安装了 msysgit (v1.7.11.msysgit.0)。在我的 .bashrc 中,我这样做了

export GIT_CONFIG=path_to_.gitconfig

当我运行git config --list 时,我得到了.gitconfig 的内容(相关摘录如下):

 ...
 alias.co=checkout
 alias.br=branch
 alias.ci=commit
 alias.st=status
 alias.logp=log --pretty=format:"%h - %an, %ar : %s"
 alias.logl=log --pretty=oneline
 alias.graph=log --pretty=format:"%h - %an : %s" --graph
 ...

但是,如果我运行 git ci -m "this is a test" 我会得到

 git: 'ci' is not a git command. See 'git --help'.

 Did you mean one of these?
    am
    citool
    commit
    config
    diff
    fsck
    gc
    init
    mv
    rm

cygwin自带的git是不是要另外设置?

【问题讨论】:

    标签: git cygwin msysgit


    【解决方案1】:

    想通了,当为新命令设置别名时,git 会尝试写入它正在加载的 .gitconfig 文件,所以我运行了git config --global alias.testalias random_git_command。然后从我的主目录

     grepc -R testalias ./
    

    我能够确定它正在使用~/.gitconfig。所以解决方案是在我的主目录中创建一个符号链接ln -s [path_to_desired_.gitconfig] .gitconfig

    仍然觉得奇怪的是,当我运行 git config --list 时,我可以看到别名列表,但是当我尝试运行它们时,git 不会将它们识别为有效别名...

    【讨论】:

    • 运行git config --global --list 可能会显示它们。这看起来在你的 ~/.gitconfig 中,而不是 repo 的本地。
    【解决方案2】:

    我通过在.bash_profile 中包含带有alias 命令的git 别名来解决这个问题:

    alias gch='git checkout'
    alias br='git branch'
    alias ci='git commit'
    alias gs='git status'
    alias gcd='git checkout develop'
    alias gcm='git checkout master'
    alias gph='git push'
    alias gpl='git pull'
    alias unstage='git reset HEAD --'
    alias ga='git add -u .'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 2011-05-10
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      相关资源
      最近更新 更多