git with --git-dir= results in 'not a git repository'

允我心安 提交于 2019-12-03 10:39:32

When using --git-dir, you need to point at the .git folder of your repository. Try:

git --git-dir=projectDirPath/.git show -s --pretty=format:%h

I use to have an issue remembering this myself. To help me remember what to do, I try to remember that the option is asking for exactly what it wants: the path to the .git directory (git-dir).

Apart of --git-dir, also setting --work-tree may help. For the script, it's good to use relevant environments (it's easier), e.g.

#!/bin/bash -ex
export GIT_WORK_TREE=/path/to/repo
export GIT_DIR=/path/to/repo/.git
git show -s --pretty=format:%h
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!