将git文件保存在另一个文件夹中 [英] keep git files in another folder

查看:107
本文介绍了将git文件保存在另一个文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置git来跟踪文件夹〜/ a 中的文件,但是存储 .git 文件夹中的文件夹〜/ b



另外,为了让这一个(巨大)在另一台服务器上保留 .git 文件夹并从服务器 a git 命令c $ c>检查 git st ,例如在服务器上 b



基本上,我希望能够在某个文件夹中使用git,而不必在同一个文件夹中保留 .git EM>。对于我上面的第二个问题,我想进一步甚至没有将 .git 目录保留在同一个服务器上



感谢!

解决方案设置 GIT_DIR 环境变量。



在bash中:

  export GIT_DIR =〜/ b 

或在PowerShell中:

  Set-Item env:GIT_DIR $ env:HOME\b 

可以在所有 git 命令中使用 - git-dir 命令行参数:

  git --gir-dir =〜/ b状态

请参阅这篇关于git环境变量的文章



关于将Git存储库目录放在另一台服务器上:好吧,只要您从该服务器挂载了文件系统并拥有适当的权限,那就可以正常工作。在本地目录上运行的git命令主要关注访问文件系统,所以它们只要运行就行。



(澄清:上面我假设〜/ b git目录,如果 .git 是<$的子目录c $ c>〜/ b ,您应该使用〜/ b / .git


How can I set up git to keep track of files in folder ~/a , but store the .git folder in folder ~/b?

Also, to take this one (huge) step further, can I keep the .git folder on another server and run git commands from server a to check git st for example, on server b?

Basically, i'd like to to able to use git on a certain folder without keeping the .git directory in that same folder. and for my second question above, i'd like to take that one step further by not even keeping the .git directory on the same server

Thanks!

解决方案

Set the GIT_DIR environment variable.

In bash:

export GIT_DIR=~/b

or, in PowerShell:

Set-Item env:GIT_DIR $env:HOME\b

Alternatively you can use the --git-dir command line parameter on all git commands:

git --gir-dir=~/b status

See this article about git environment variables

About putting the Git repository directory on another server: well, as long as you have mounted the file system from that server and have appropriate permissions, that should work fine. The git commands that operate on your local directory care mostly about accessing the file system, so they work as long as that works.

(To clarify: Above I am assuming that ~/b is the git directory, if .git is a subdirectory of ~/b, you should use ~/b/.git instead)

这篇关于将git文件保存在另一个文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆