我可以将.git目录移动到它的父目录中吗? [英] Can I move the .git directory for a repo to it's parent directory?
问题描述
PPP /
| --ABC /
| | - 。git /
| | --AAA /
| | BBB /
| | CCC /
|
| --DEF /
| | - 。git /
| | --DDD /
| | --EEE /
并且想将它们组合成一个repo,所以我假设目录结构将如下所示:
PPP /
| - 。git /
| - ABC /
| | --AAA /
| | --BBB /
| | --CCC /
|
| --DEF /
| | --DDD /
| | --EEE /
这是可以吗?
目前,还有几个人在他们的机器上有回收。多少更复杂的生活?
Ta。
你可以这样做:
-
移动
ABC
到ABC /
子目录,并修复历史记录,使其看起来一直存在:$ cd / path / to / ABC
$ git filter-branch --index-filter \
'git ls-files -s | seds-\t-& ABC / - |
GIT_INDEX_FILE = $ GIT_INDEX_FILE.new \
git update-index --index-info&&
mv $ GIT_INDEX_FILE.new $ GIT_INDEX_FILE'HEAD
现在你的目录结构是
ABC / ABC / your_code
-
与
DEF
:$ cd / path / to / DEF
$ git filter-branch --index-filter \\ \\
'git ls-files -s | seds-\t-& DEF / - |
GIT_INDEX_FILE = $ GIT_INDEX_FILE.new \
git update-index --index-info&&
mv $ GIT_INDEX_FILE.new $ GIT_INDEX_FILE'HEAD
现在你的目录结构是
DEF / DEF / your_code
-
最后,创建
PPP
存储库,并将ABC
和DEF
中的$ mkdir / path / to / PPP
$ cd / path / to / PPP
$ git init
$ git pull / path / to / ABC
$ git pull / path / to / DEF
现在你有
PPP / ABC / your_code
和PPP / DEF / your_code
以及所有历史记录。
您可能会要求您的同事在其系统上运行以前的命令,以便每个人都能同步。
I have two sub-directories each with a repo, thus :
PPP/
|--ABC/
| |--.git/
| |--AAA/
| | BBB/
| | CCC/
|
|--DEF/
| |--.git/
| |--DDD/
| |--EEE/
And would like to combine them into one repo, so, I would assume the directory structure would be like this:
PPP/
|--.git/
|--ABC/
| |--AAA/
| |--BBB/
| |--CCC/
|
|--DEF/
| |--DDD/
| |--EEE/
Is this posible?
Also currently several people have the repos on their machines. How much more complicated does that make life?
Ta.
You can do what you are describing like this:
Move the content of
ABC
to anABC/
subdirectory, and fix the history so that it looks like it has always been there:$ cd /path/to/ABC $ git filter-branch --index-filter \ 'git ls-files -s | sed "s-\t-&ABC/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new \ git update-index --index-info && mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
Now your directory structure is
ABC/ABC/your_code
Same for the content of
DEF
:$ cd /path/to/DEF $ git filter-branch --index-filter \ 'git ls-files -s | sed "s-\t-&DEF/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new \ git update-index --index-info && mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
Now your directory structure is
DEF/DEF/your_code
Finally, create the
PPP
repository and pull bothABC
andDEF
into it:$ mkdir /path/to/PPP $ cd /path/to/PPP $ git init $ git pull /path/to/ABC $ git pull /path/to/DEF
Now you have
PPP/ABC/your_code
andPPP/DEF/your_code
, along with all the history.
You should probably ask you collegues to run the previous commands on their system, in order for everyone to be synchronized.
Note: the funky
filter-branch
commands come from the man page. :-)
这篇关于我可以将.git目录移动到它的父目录中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!