Git svn fetch 然后提交到远程 git

Git svn fetch and then commit to remote git

我的客户有一个 SVN 存储库,我想在我这边使用 git。我使用 git-svn 从我客户的 svn 创建了一个 git 并为它创建了一个 gitlab。如果我的客户更改了他这边的某些内容,我想获取更改,然后更新我的 gitlab 以保持一切同步。

目前我正在使用:

git svn fetch 

如果有什么改变,我会得到一些改变。收到更改后,我仍然无法将所述更改推送到我的 git.

git commit -am "Changed something"

returns:

Your branch is up-to-date with xxx

nothing to commit, working directory clean

显然发生了一些变化,但我的 git 不会注意到。 我错过了什么?

tl;博士

如果你想让你的 GitLab 存储库与 Subversion 存储库保持同步,你应该 运行 这些命令:

# Fetch the latest commits from SVN and merge them into the current branch
git svn rebase

# Push the new commits to GitLab
git push origin

背景

从逻辑上讲,当您 运行 git svn fetch 您从 SVN 存储库接收新的 提交 – 而不是文件。

这就是您在尝试创建新提交时收到该错误消息的原因:Git 告诉您您的工作目录中没有任何修改过的文件。

git svn fetch 会将新的提交下载到您的存储库中,但它 不会自动将它们合并 到当前分支中。为此,您应该 运行:

git svn rebase

documentation 对此的评价如下:

You can run git svn fetch to grab the new data, but git svn rebase does the fetch and then updates your local commits.

请记住,当您 运行 git svn rebase:

时,您的工作目录中不应有任何修改过的文件

You need to be sure your working directory is clean when you run this, though. If you have local changes, you must either stash your work or temporarily commit it before running git svn rebase — otherwise, the command will stop if it sees that the rebase will result in a merge conflict.

提取并合并提交后,您可以通过以下方式将它们发布到您的 GitLab 存储库:

git push origin

其中 origin 是指向 GitLab 存储库的远程名称。