我正在编写一些脚本来获取有关我在本地设置的git存储库的信息。最好用一个简单的例子来解释:
machine:~ anon$ mkdir test
machine:~ anon$ cd test
machine:test anon$ mkdir myrepo
machine:test anon$ cd myrepo/
machine:myrepo anon$ git init
Initialized empty Git repository in /Users/anon/test/myrepo/.git/
machine:myrepo anon$ echo this is a test >> test.txt
machine:myrepo anon$ git add test.txt
machine:myrepo anon$ git commit -m "first commit"
[master (root-commit) d9b8bf0] first commit
1 file changed, 1 insertion(+)
create mode 100644 test.txt
machine:myrepo anon$ git status
# On branch master
nothing to commit (working directory clean)
machine:myrepo anon$ git log
commit d9b8bf02d5ff8b214d3ac44308c53ee6c8bcaac5
Author: Anon Ymus <anon@website.com>
Date: Mon Feb 3 13:22:17 2014 +0000
first commit
machine:myrepo anon$ cd ~
machine:~ anon$ git status ${HOME}/test/myrepo/
fatal: Not a git repository (or any of the parent directories): .git
如果工作目录位于git仓库中,我只能获取有关我的仓库的信息。
我可以修改我的脚本,将工作目录更改为git repo然后再返回。但是我希望尽可能避免这种情况,因为我的脚本既适用于SVN,也适用于GIT。例如,使用SVN命令,如:
svn info /this/is/a/fullpath
无论路径或工作目录是什么,都能正常工作,所以为了保持一致,我希望尽可能贴近这个解决方案。
提前致谢:)
答案 0 :(得分:1)
git --git-dir=the/local/repo/.git --work-tree=the/local/repo status