Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git释放了SVN标记之间的历史轨迹_Git_Svn_Git Svn - Fatal编程技术网

git释放了SVN标记之间的历史轨迹

git释放了SVN标记之间的历史轨迹,git,svn,git-svn,Git,Svn,Git Svn,我的git回购正在跟踪SVN回购。我的一个git分支,我们称之为“latest_标记”,指向源代码,因为它位于最新的SVN标记中。创建新的SVN标记时,我希望合并“latest_标记”中的更改。当我尝试这样做时,git抱怨合并冲突,好像它不了解SVN历史一样 SVN回购协议采用标准结构 trunk/ tags/ - v1 branches/ 我为每个SVN标记创建了git分支,并创建了一个“latest_tag”分支 git branch v1 tags/v1 git branch lates

我的git回购正在跟踪SVN回购。我的一个git分支,我们称之为“latest_标记”,指向源代码,因为它位于最新的SVN标记中。创建新的SVN标记时,我希望合并“latest_标记”中的更改。当我尝试这样做时,git抱怨合并冲突,好像它不了解SVN历史一样

SVN回购协议采用标准结构

trunk/ tags/ - v1 branches/ 我为每个SVN标记创建了git分支,并创建了一个“latest_tag”分支

git branch v1 tags/v1
git branch latest_tag v1
当在SVN repo(例如v2)中添加新标记时,我可以将其导入git repo

git svn fetch
git branch v2 tags/v2
但是如果我尝试将“最新标签”分支从v1快进到v2,我会得到一个错误

$ git checkout latest_tag
$ git merge v2
Auto-merging source.py
CONFLICT (add/add): Merge conflict in source.py
Automatic merge failed; fix conflicts and then commit the result.
当我查看冲突时,看起来git认为v1和v2之间的所有更改都是不相关的,尽管它们有一个共同的历史记录

下面是一个重新创建问题的最小脚本

# Create the svn repo and its first tag.
svnadmin create svn_repo/
svn checkout "file:///${PWD}/svn_repo/" svn_working_copy
( cd svn_working_copy ; mkdir -p trunk tags branches ; svn add * ; svn commit -m 'Initialize SVN repo' ; cd trunk ; echo "print 'Hello v1'" >source.py ; svn add * ; svn commit -m 'Development for v1' ; cd .. ; svn cp trunk/ tags/v1 ; svn commit -m 'Tag v1' ; sed --in-place 's/v1/v2/' trunk/* ; svn commit -m 'Development for v2' ; )

# Create a git repo from the svn repo.
git svn clone --stdlayout "file://${PWD}/svn_repo/" git_repo
( cd git_repo ; git branch v1 tags/v1 ; git branch latest_tag v1 )

# Create tag v2 in svn.
( cd svn_working_copy ; svn cp trunk/ tags/v2 ; svn commit -m 'Tag v2' )

# Merge or rebase 'latest_tag' git branch on svn tag v2.
( cd git_repo ; git svn fetch ; git branch v2 tags/v2 ; git checkout latest_tag ; git merge v2 )
编辑 我确认git似乎并没有意识到两个SVN标签之间的共同历史

$ git log --oneline master
bd050cd Development for v2
373f808 Development for v1
3b92703 Initialize SVN repo
$ git log --oneline remotes/tags/v1
31f9fff Tag v1
3b92703 Initialize SVN repo
$ git log --oneline remotes/tags/v2
b717759 Tag v2
3b92703 Initialize SVN repo
如果git理解SVN历史,它将输出这个

$ git log --oneline remotes/tags/v1
31f9fff Tag v1
373f808 Development for v1
3b92703 Initialize SVN repo
$ git log --oneline remotes/tags/v2
b717759 Tag v2
bd050cd Development for v2
373f808 Development for v1
3b92703 Initialize SVN repo

我发现了为什么git似乎对svn的历史一无所知。答案是:这取决于如何创建svn标记

查看svn历史记录,我发现svn标记是由不同版本的文件组成的,而不是作为给定版本的快照创建的

$ svn log -v
------------------------------------------------------------------------
r3 | lacton | 2013-07-27 18:15:20 | 1 line
Changed paths:
   A /tags/v1 (from /trunk:1)
   A /tags/v1/source.py (from /trunk/source.py:2)

Tag v1
------------------------------------------------------------------------
尽管svn似乎对此非常满意,但git svn对此感到困惑

在创建标记之前添加
svn更新
,可以修复此问题

$ svn up
At revision 2.
$ svn cp trunk/ tags/v1
A         tags/v1
$ svn commit -m 'Tag v1'
Adding         tags/v1

Committed revision 3
$ svn up
At revision 3.
$ svn log -v -r HEAD
------------------------------------------------------------------------
r3 | lacton | 2013-07-27 18:20:26 | 1 line
Changed paths:
   A /tags/v1 (from /trunk:2)

Tag v1
------------------------------------------------------------------------
通过此修复,git svn可以正确解释svn标记历史,不再存在合并冲突

下面是与初始问题一起提供的最小脚本的“git友好”版本(即,在创建标记之前使用
svn update

# Create the svn repo and its first tag.
svnadmin create svn_repo/
svn checkout "file:///${PWD}/svn_repo/" svn_working_copy
( cd svn_working_copy ; mkdir -p trunk tags branches ; svn add * ; svn commit -m 'Initialize SVN repo' ; cd trunk ; echo "print 'Hello v1'" >source.py ; svn add * ; svn commit -m 'Development for v1' ; cd .. ; svn up ; svn cp trunk/ tags/v1 ; svn commit -m 'Tag v1' ; sed --in-place 's/v1/v2/' trunk/* ; svn commit -m 'Development for v2' ; )

# Create a git repo from the svn repo.
git svn clone --stdlayout "file://${PWD}/svn_repo/" git_repo
( cd git_repo ; git branch v1 tags/v1 ; git branch latest_tag v1 )

# Create tag v2 in svn.
( cd svn_working_copy ; svn up ; svn cp trunk/ tags/v2 ; svn commit -m 'Tag v2' )

# Merge or rebase 'latest_tag' git branch on svn tag v2.
( cd git_repo ; git svn fetch ; git branch v2 tags/v2 ; git checkout latest_tag ; git merge v2 )
# Create the svn repo and its first tag.
svnadmin create svn_repo/
svn checkout "file:///${PWD}/svn_repo/" svn_working_copy
( cd svn_working_copy ; mkdir -p trunk tags branches ; svn add * ; svn commit -m 'Initialize SVN repo' ; cd trunk ; echo "print 'Hello v1'" >source.py ; svn add * ; svn commit -m 'Development for v1' ; cd .. ; svn up ; svn cp trunk/ tags/v1 ; svn commit -m 'Tag v1' ; sed --in-place 's/v1/v2/' trunk/* ; svn commit -m 'Development for v2' ; )

# Create a git repo from the svn repo.
git svn clone --stdlayout "file://${PWD}/svn_repo/" git_repo
( cd git_repo ; git branch v1 tags/v1 ; git branch latest_tag v1 )

# Create tag v2 in svn.
( cd svn_working_copy ; svn up ; svn cp trunk/ tags/v2 ; svn commit -m 'Tag v2' )

# Merge or rebase 'latest_tag' git branch on svn tag v2.
( cd git_repo ; git svn fetch ; git branch v2 tags/v2 ; git checkout latest_tag ; git merge v2 )