git: a quick command to go to root of the working tree

前端 未结 7 1769
悲&欢浪女
悲&欢浪女 2020-12-24 01:21

I wanted a simple git command to go up to the \"root\" of the repository.

I started with a script, but figured that I cannot change active directory of the shell, I

7条回答
  •  梦毁少年i
    2020-12-24 01:45

    Unfortunately, changing your current directory can only be done by the shell, not by any subprocess. By the time git gets around to parsing your command, it's already too late -- git has already been spawned in a separate process.

    Here's a really gross, untested shell function that just might do what you want:

    function git() {
        if [ "$1" == "root" ]; then
            git-root
        else
            git "$@"
        fi
    }
    

提交回复
热议问题