English 中文(简体)
我如何在没有存放处的情况下执行Gite指挥部?
原标题:How do I execute a Git command without being in the repository?
  • 时间:2011-08-22 15:42:56
  •  标签:
  • git

是否有办法执行 未经存放地就对存放处进行突击检查?

例如:git /home/repolog?

请不要告诉我<条码>cd。 页: 1

最佳回答

Try:

git --git-dir=/home/repo/.git log

重要的是,要给您的存放地目录提供一切途径。 否则,你只能得到一个错误的信息,即:

fatal: Not a git repository
问题回答

使用<条码>-C作为第一种理由:

git -C /home/repo log

Per docs,其效果是:

-C <path>

如同在<代码><path>而不是现行工作名录上开始使用。 ......

This is almost equivalent to --git-dir and --work-tree without appending the usual .git folder. However, the options --git-dir and --work-tree do not exist to access the repository from outside the work tree; they are used to move the .git somewhere else, and they are much more complicated to use in some cases.

For instance, to get the log of /home/repo/subdir only:

git -C /home/repo/subdir log .

or

git -C /home/repo log subdir

It is not possible to use log . with --git-dir or --work-tree. The path must be processed to extract the subpath relative to the top of the work tree, and even in that case, git will not recognize it as a path if you do not use the -- option, so the only possible way is:

git --git-dir /home/repo/.git log -- subdir

Furthermore, --work-tree does not work at all with the log subcommand with my version (git 1.9.1). It is just ignored:

git --git-dir /home/repo/.git --work-tree /home/repo/subdir log -- subdir
git --git-dir /home/repo/.git --work-tree /home/repo/whatever log -- subdir

I do not even understand if this is a bug or a feature... as usual with many git design choices.

In fact you need to use --git-dir and --work-tree together. Here is an example:

local [] Desktop: mkdir git
local [] Desktop: cd git
local [] git: touch README.txt
local [] git: git init
Initialized empty Git repository in /Users/albert/Desktop/git/.git/
local [] git: cd ..
local [] Desktop: git --work-tree=git --git-dir=git/.git add .
local [] Desktop: git --work-tree=git --git-dir=git/.git commit -a -m  initial commit, called from outside the git directory 
[master (root-commit) ee951b1] initial commit, called from outside the git directory
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.txt
local [] Desktop: cd git
local [] git: git log --pretty=oneline
ee951b161053e0e0948f9e2a36bfbb60f9c87abe initial commit, called from outside the git di

I have tried many times! I finally got it!

git - C 继承 --no-pager log --format= %an -1 filename

do remember, please don t add .git to your

- C 继承

对于任何上级指挥,你可以:

git --git-dir=<PATH-TO-REPO>/.git --work-tree=<PATH-TO-REPO> <git-command>

例如,如果你想做某种身份的话:

 git --git-dir=/home/myrepo/.git --work-tree=/home/myrepo/  status

或者如果你想要检查分行,寄回的地址是:

git --git-dir=/home/myrepo/.git --work-tree=/home/myrepo/  rev-parse --abbrev-ref HEAD

这类似于@max的答复。 不幸的是,我不做我所需要的事。 在回顾中,另一个[以前的]回答是,建议使用<条码>-工作-特里<>。 我不敢确定使用环境或旗帜是否更为合适,因此,如果有人在座,我就离开我的答案,但我将转而使用<代码>--work-tree/--git-dir


There s two repos, one inside the other but not a submodule; the outer repo ignores it:

tools (outer repo)
  gcc/4.9.2 (inner repo)

What I wanted was the output of git rev-parse --show-prefix relative to the outer repo. Here s what I came up with (bash syntax; split across lines for readability):

prefix_dir=$(cd ..; git rev-parse --show-toplevel)
prefix_dir=$(GIT_WORK_TREE=${prefix_dir} git rev-parse --show-prefix)

When executed from within 4.9.2 it produces the string gcc/4.9.2.





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签