Sor*_*rcy 69 git repository hierarchy
Git初学者问题:
我有一个小的私人webproject,使用msysgit在本地进行版本控制.没有外部存储库,因为它只适用于我,所以我可以基本上做任何我想做的事情.
我已经在项目目录中设置了这个,即在"webroot"中.
现在必须创建第二个目录,与webroot平行放置.我们称之为资产.
所以结构现在如下:
\ project directory
----\webroot
----\assets
Run Code Online (Sandbox Code Playgroud)
我想在git存储库中包含这个新目录,这样我也会对存储在那里的文件进行版本更改,但当然我不能使用"git add ../assets".我也不倾向于在project_directory中创建一个新的git项目,因为这会松开我以前的所有提交.
那么如何将存储库从"webroot"移动到"project_directory",同时保留我的提交然后能够包含"资产"?
Tim*_*gan 66
所以,你希望你的git repo看起来像这样:
<projectdir>
/.git
/webroot
/assets
Run Code Online (Sandbox Code Playgroud)
为此,您必须将repo中的现有文件移动到新的webroot子目录中.
cd <git repo root>
mkdir webroot
git mv <all your files> webroot
git commit --all -m "moved all existing files to new 'webroot' directory"
Run Code Online (Sandbox Code Playgroud)
然后,在您的本地文件系统上,您希望将克隆重定位到上面的目录:
cd <projectdir>
mv webroot/* .
rmdir webroot
Run Code Online (Sandbox Code Playgroud)
然后你想将assets目录(和文件)添加到git repo:
git add assets
git commit -m "added assets to the repo"
Run Code Online (Sandbox Code Playgroud)
bra*_*sch 16
您也可以将.git目录向上移动一级并更新您的工作树.
cd projectdir
mv ./webroot/.git ./.git
git config core.worktree /absolute-path-to-project-dir
git add assets
git commit -m 'adding assets folder'
Run Code Online (Sandbox Code Playgroud)
不是积极的,但我很确定core.worktree的路径必须是绝对的.
seh*_*ehe 11
我假设您打算重写历史记录以包含所有修订版中的所有文件,就好像它们一直位于webroot /而不是根目录中的子目录中一样
git filter-branch联机帮助页有答案,这里是一个改进的版本,它重写了所有现有的引用(分支)和标记:
time git filter-branch --index-filter 'git ls-files -s |
sed "s-\t\"*-&webroot/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' --tag-name-filter cat -- --all
Run Code Online (Sandbox Code Playgroud)
已经注意使这成为仅索引操作,以便即使对于大回购也可以快速运行.记住(当满意时)摆脱原始引用(.git/refs/original/*)并重新打包repo以松开过时的树对象.
您的提交不是本地绑定到它们存储在git仓库中的"webroot"文件夹.
你可以简单地删除webroot目录,重新检查新位置"/ project目录"中的存储库添加资产目录并提交.
rm -Rf webroot
git clone path-to-repo
git add assets
git commit -m "Added assets directory"
git push
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25818 次 |
| 最近记录: |