简体   繁体   English

如何使本地svn-git存储库与.svn保持同步?

[英]How can I keep a local svn-git repo in sync with .svn?

I am working on a project that uses SVN as repository which I use in combination with the Netbeans SVN plugin. 我正在使用SVN作为存储库的项目,该项目与Netbeans SVN插件结合使用。 I found Netbeans SVN diff lacking on showing several diffs below each other and therefore wanted to use git-svn for being able to use git gui . 我发现Netbeans SVN差异缺少在彼此之间显示几个差异,因此想要使用git-svn来使用git gui

The problem is now keeping both repositories in sync. 现在的问题是使两个存储库保持同步。 My current workflow is: 我当前的工作流程是:

  • Updating (with no local changes): 更新(无本地更改):

     svn up git stash -u # include new files too git svn rebase git stash drop 
  • Comitting: 承诺:

     git commit git commit ... git svn dcommit 

These base cases do work, but it does not work nicely if I have local unstaged/uncomitted changes. 这些基本情况确实有效,但是如果我进行了本地未暂存/未提交的更改,则无法很好地工作。

What is a better way to keep the local git-svn and .svn in sync? 有什么更好的方法来保持本地git-svn和.svn同步?

I have found a workaround that works pretty well. 我找到了一种很好的解决方法。 The idea is to keep files updated using subversion and have git only update its history without touching any files in the working tree. 这个想法是使用subversion来保持文件更新,而git只更新其历史记录而不会触及工作树中的任何文件。 git svn created a special git-svn branch which contains the latest subversion code once fetched. git svn创建了一个特殊的git-svn分支,其中包含了一旦被获取的最新的Subversion代码。

The commands to update your files, followed by a git repo history update: 用于更新文件的命令,然后更新git repo历史记录:

svn up
git svn fetch
git reset --mixed git-svn

The last git reset --mixed command is necessary to ensure that git knows that your files are from the last SVN revision. 最后一个git reset --mixed命令是必需的,以确保git知道您的文件来自上一个SVN版本。 Note that this command will reset any commits you made with git commit (remove commit messages, not the changes). 请注意,此命令将重置您使用git commit所做的所有git commit (删除提交消息,而不是更改)。 As a solution for that, commit via svn commit and fetch your history as shown above. 作为解决方案,请通过svn commit并获取您的历史记录,如上所示。

git reset --mixed git-svn somehow unables you to commit to use dcommit . git reset --mixed git-svn某种程度上使您无法承诺使用dcommit After running git reset --mixed git-svn , follow the following sequence to commit using git: 运行git reset --mixed git-svn ,请按照以下顺序使用git进行提交:

git stash
git svn rebase
git stash pop
git commit ...
git svn dcommit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM