英文:
SVN to Git using git svn - keeping git updated
问题
I am migrating from SVN to git using the git-svn plugin.
我正在使用git-svn插件从SVN迁移到git。
I cloned the SVN repo with history and that worked.
我克隆了包含历史记录的SVN仓库,这部分成功了。
I was able to push into my Gitlab 'main' branch in my new repository.
我成功推送到了我的新仓库的Gitlab 'main'分支。
And when I do a git svn fetch
I see the changes from my SVN repo.
当我运行git svn fetch
时,我可以看到来自我的SVN仓库的更改。
And doing git log --all shows the revisions.
运行git log --all会显示修订版本。
But nothing I do seems to push the new change up to the git Repo.
但是我所做的一切似乎都不能将新更改推送到git仓库。
git branches (I did not need to migrate any tags or branches other than trunk)
git分支(我不需要迁移除trunk之外的标签或分支)
~/GitMigration/Blah-Main $ git branch
~/GitMigration/Blah-Main $ git branch -r
origin/main
origin/trunk
The original push into the git repo main branch I had to do a -f but even that doesnt seem to do anything
最初推送到git仓库的main分支时,我不得不使用-f选项,但似乎仍然没有效果
~/GitMigration/Blah-Main $ git branch -a
main
remotes/origin/main
remotes/origin/trunk
~/GitMigration/Blah-Main $
~/GitMigration/Org-Main $ git push origin main
Everything up-to-date
svn-remote.svn.url=https://svn.com/Org/svn
svn-remote.svn.fetch=Org/trunk:refs/remotes/origin/trunk
svn-remote.svn.branches=Org/branches/:refs/remotes/origin/
svn-remote.svn.tags=Org/tags/:refs/remotes/origin/tags/
svn.authorsfile=/Users/user/GitMigration/authors.txt
remote.origin.url=https://gitlab.com/org/org-main.git
remote.origin.fetch=+refs/heads/:refs/remotes/origin/
branch.main.remote=origin
branch.main.merge=refs/heads/main
英文:
I am migrating from SVN to git using the git-svn plugin.
I cloned the SVN repo with history and that worked. I was able to push into my Gitlab 'main' branch in my new repository. And when I do a git svn fetch
I see the changes from my SVN repo. And doing git log --all shows the revisions.
But nothing I do seems to push the new change up to the git Repo.
git branches (I did not need to migrate any tags or branches other than trunk)
~/GitMigration/Blah-Main $ git branch
* main
~/GitMigration/Blah-Main $ git branch -r
origin/main
origin/trunk
The original push into the git repo main branch I had to do a -f but even that doesnt seem to do anything
~/GitMigration/Blah-Main $ git branch -a
* main
remotes/origin/main
remotes/origin/trunk
~/GitMigration/Blah-Main $
~/GitMigration/Org-Main $ git push origin main
Everything up-to-date
svn-remote.svn.url=https://svn.com/Org/svn
svn-remote.svn.fetch=Org/trunk:refs/remotes/origin/trunk
svn-remote.svn.branches=Org/branches/*:refs/remotes/origin/*
svn-remote.svn.tags=Org/tags/*:refs/remotes/origin/tags/*
svn.authorsfile=/Users/user/GitMigration/authors.txt
remote.origin.url=https://gitlab.com/org/org-main.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
答案1
得分: 1
问题在于你正在推送main
(本地的main
),这并不是正确的要推送的分支。鉴于你的svn分支显然是origin/trunk
,你应该运行以下命令将其推送到origin/main
:
git push origin origin/trunk:main
这里需要理解的关键是,对于git来说,一切都是关于提交的... 而分支只是指向提交的“指针”。svn分支并不是(本地的)main
,而是origin/trunk
,因此,在运行git svn fetch
同步后,移动的是origin/trunk
,所以我们需要推送那个提交到origin/main
... 这就是我在那个命令中使用的命令(将该命令拆分开,它是:git push <some-remote> <some-commit>:<remote-branch>
)。
附带说明:
我有点不太喜欢你将git-svn
设置为将svn分支映射到origin
,可能应该保持svn仓库和实际git仓库为不同的远程(这样svn分支可能会显示为svn/trunk
,例如)... 如果是这样的话,在git svn fetch
之后,你会运行:
git push origin svn/trunk:main
这看起来更好得多,但是,正如我们所看到的,保持你现在的设置也是可行的。
英文:
The problem is that you are pushing main
(local main
), which is not the right branch to push. Given that your svn branch is (apparently) origin/trunk
, you should run this to have it show up in origin/main
:
git push origin origin/trunk:main
The trick to understand here is that to git, it's all about commits.... and branches are just pointers to commits. The svn branch is not (local) main
, it's origin/trunk
, so, after running git svn fetch
to sync up, what has moved is origin/trunk
and so we need to push that commit to origin/main
... hence the command I used there (breaking up that command, it is: git push <some-remote> <some-commit>:<remote-branch>
).
Side note:
It bugs be a little bit that you set git-svn
to map the svn branch to origin
, should probably keep the svn repo and the real git repo as different remotes (so that the svn branch could show up as svn/trunk
, for example)... if that were the case, after git svn fetch
, you would run:
git push origin svn/trunk:main
Which looks a lot better but, as we can see, it's possible to keep it the way you have it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论