我尝试将一个目录及其所有历史记录从一个存储库移动到另一个存储库。
使用
这会创建一个新分支,可以轻松地获取到其他存储库。
现在我使用
如果我查看
但是当我尝试使用
为什么在上面的gitk中看到提交,但在单个文件的日志中没有看到?
如果我进行简单的
将已移动的提交集成到另一个存储库的正确方法是什么?
复制示例命令以重现该情况:
使用
git subtree split
可以轻松提取完整的目录历史记录。这会创建一个新分支,可以轻松地获取到其他存储库。
现在我使用
git subtree add
将目录粘贴回第二个存储库。如果我查看
gitk
或git log --decorate --graph
,一切看起来都很好。所有提交都按预期出现。所有文件也按预期出现。但是当我尝试使用
git log -- transplanted_dir/somefile
查看移植文件的历史记录时,我只能看到一个“合并”提交,这是由于git subtree add
产生的。为什么在上面的gitk中看到提交,但在单个文件的日志中没有看到?
如果我进行简单的
git merge
,我可以看到每个文件的历史记录,但文件当然不会在子文件夹中。将已移动的提交集成到另一个存储库的正确方法是什么?
复制示例命令以重现该情况:
#create two repositories:
git init a
git init b
# create directory dir with some history
cd a
mkdir dir
echo 1 > dir/file
git add .
git commit -am 1
echo 2 > dir/file
git commit -am 2
echo 3 > dir/file
echo 3 > otherfile
git add .
git commit -am 3
#split subtree
git subtree split --prefix dir -b split
#create a commit on repo b
cd ../b
mkdir otherdir
touch otherdir/file
git add .
git commit -am init
#fetch split branch of repo a
git fetch ../a split
git co -b split FETCH_HEAD
git log --decorate --graph --name-status
git co master
# add commits to repo b
git subtree add --prefix somedir split
# this looks fine:
git log --decorate --graph --name-status
# no history here - Why?
git log --decorate --graph --name-status somedir/file
git log --decorate --graph --name-status --follow somedir/file
git log
命令只会停留在重命名的那个点;在更早的时间,那个文件是不存在的。 - mattfoo/bar/baz
移动到bar/baz
被视为重命名。git log --follow
的输出是什么? - gcbenison