当我的磁盘安装在其他服务器上时如何找到我所在的 git 分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5059441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find which git branch I am on when my disk is mounted on other server
提问by user79292
Our git repo is on a Linux server; I can be on the master branch or create a new branch that I can go inside and use.
我们的 git 仓库在 Linux 服务器上;我可以在主分支上,也可以创建一个可以进入并使用的新分支。
Our git repo disk is mounted on AIX box to build (I can see git directory in the AIX box that allows me to build)
我们的git repo磁盘挂载在AIX box上进行构建(我可以在AIX box中看到git目录允许我构建)
In the AIX box how I can see that I am using master or inside a particular branch. What changes inside .git that drives which branch I am on?
在 AIX 框中,我如何看到我正在使用 master 或在特定分支内。.git 内部的哪些变化驱动了我所在的分支?
回答by ralphtheninja
git branch
with no arguments displays the current branch marked with an asterisk in front of it:
git branch
不带参数显示当前分支前用星号标记:
user@host:~/gittest$ git branch
* master
someotherbranch
In order to not have to type this all the time, I can recommend git prompt:
为了不必一直输入这个,我可以推荐 git prompt:
http://volnitsky.com/project/git-prompt/
http://volnitsky.com/project/git-prompt/
In the AIX box how I can see that I am using master or inside a particular branch. What changes inside .git that drives which branch I am on?
在 AIX 框中,我如何看到我正在使用 master 或在特定分支内。.git 内部的哪些变化驱动了我所在的分支?
Git stores the HEAD
in the file .git/HEAD
. If you're on the master
branch, it could look like this:
Git 将 存储HEAD
在文件中.git/HEAD
。如果您在master
分支上,它可能如下所示:
$ cat .git/HEAD
ref: refs/heads/master
回答by Andrew Thomas
Try using the command: git status
尝试使用命令:git status
回答by Matt Enright
You can look at the HEAD pointer (stored in .git/HEAD
) to see the sha1 of the currently checked-out commit, or it will be of the format ref: refs/heads/foo
for example if you have a local ref foo
checked out.
您可以查看 HEAD 指针(存储在 中.git/HEAD
)以查看当前检出提交的 sha1,或者ref: refs/heads/foo
如果您foo
检出本地引用,则它将采用这种格式。
EDIT: If you'd like to do this from a shell, git symbolic-ref HEAD
will give you the same information.
编辑:如果您想从 shell 执行此操作,git symbolic-ref HEAD
将为您提供相同的信息。
回答by poke
.git/HEAD
contains the path of the current ref, the working directory is using as HEAD.
.git/HEAD
包含当前 ref 的路径,工作目录用作 HEAD。
回答by Robin Daugherty
Our git repo disk is mounted on AIX box to do BUILD.
我们的 git repo 磁盘安装在 AIX 机器上来做 BUILD。
It sounds like you mounted the drive on which the git repository is stored on another server, and you are asking how to modify that. If that is the case, this is a bad idea.
听起来您将存储 git 存储库的驱动器安装在另一台服务器上,并且您正在询问如何修改它。如果是这样的话,这是一个坏主意。
The build server should have its own copy of the git repository, and it will be locally managed by git
on the build server.
The build server's repository will be connected to the "main" git repository with a "remote", and you can issue the command git pull
to update the local repository on the build server.
构建服务器应该有自己的 git 存储库副本,并且将由git
构建服务器在本地管理。构建服务器的存储库将通过“远程”连接到“主”git 存储库,您可以发出命令git pull
来更新构建服务器上的本地存储库。
If you don't want to go to the trouble of setting up SSH or a gitolite server or something similar, you can use a file path as the "remote" location. So you could continue to mount the Linux server's file system on the build server, but instead of running the build out of that mounted path, clone the repository into another folder and run it from there.
如果您不想麻烦设置 SSH 或 gitolite 服务器或类似的东西,您可以使用文件路径作为“远程”位置。因此,您可以继续在构建服务器上挂载 Linux 服务器的文件系统,但不是在该挂载路径之外运行构建,而是将存储库克隆到另一个文件夹并从那里运行它。