1

I have a main repository on SVN, which I am synchronizing with a "clone" on Git / GitHub. Every time I do something on SVN, I run the following commands on my Git console:

git svn rebase
git push --force git@github.com:.../

I am frequently making mistakes when dealing with this setup (who knows how...). This leads to a lot of errors and merges, stashing, committing, adding, whatnot, which I am unable to resolve due to my lack of knowledge of Git. So I'm wondering, how can I revert all unwanted changes in my Git repository, overwriting everything the way it is committed on SVN trunk? I only ever want to commit to SVN. Git / GitHub should only be a copy.

I figured out that the workaround to run for my current problem is this:

git svn rebase
git add .
git rebase --continue
git push --force git@github.com:.../

These two additional steps allow me to continue working, as git won't complain any longer. But I don't want to keep my weird local changes. In other words, is there a command like this:

git svn "override and update"
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • Git is too complex, any mistake implies wasting hours. You should have a look at bazaar http://bazaar.canonical.com/en/ – Yves Martin Mar 17 '12 at 22:18
  • @YvesMartin: Using yet another revision control system is not an option for me – Lukas Eder Mar 18 '12 at 08:03
  • Could you please clarify what errors are you running into? remotes/... branch should not be affected by your mess, thus "checkout master; git reset remotes/trunk" should bring your master to the state of svn trunk. – Vladimir Sitnikov Mar 21 '12 at 19:37
  • @VladimirSitnikov: You mean `git reset` or `git svn reset`? I've tried the latter... The problem is (in this case, I've had many other problems in the past), that I seem to have some changes which I'm not aware of having done, in my local git repository. I'll update the question with the workaround I'm currently applying – Lukas Eder Mar 22 '12 at 08:36
  • I've amended my original answer to add the command to clean the cruft from your local git-svn tree. – idlethread Mar 22 '12 at 13:40
  • 1
    By the way, if you want to learn more about Git (and you probably should), the [Pro Git book](http://progit.org/book/) is quite nice. – robinst Mar 22 '12 at 15:28

2 Answers2

3

You said "I only ever want to commit to SVN." so I think you should take a look at GitHub's svn-support which was updated for some months ago to also support pushing directly from svn.

Code example from GitHub;

$ echo '# Important change' >> branches/wip/README.md
$ svn commit -m 'Made an important change'
Sending        branches/wip/README.md
Transmitting file data .
Committed revision 27.

...and it works ;) By using this you do not need to use git.

Mattias
  • 9,211
  • 3
  • 42
  • 42
  • Hmm, but this would mean I'd have to use GitHub as my primary repository, which I don't want to do right now...? – Lukas Eder Mar 17 '12 at 19:37
  • O sorry, my fault (I live in the Git world) so i thought that svn can handle multiple remotes like Git. But I think you should take a look at this link http://stackoverflow.com/questions/320759/synchronizing-code-with-two-subversion-repositories – Mattias Mar 18 '12 at 09:23
  • That might be another option... But I really really hope that my simple question will have an answer. I just want to throw away the Git repository state and restore it again from SVN... It seems like a basic feature for `git-svn` to me, but apparently, it is not... – Lukas Eder Mar 18 '12 at 09:32
  • I´m out of ideas, but there can be some good stuff at the ProGit Book http://progit.org/book/ch8-1.html where they talk about `git-svn`. – Mattias Mar 18 '12 at 10:13
  • Thanks for that link. I'll have a look later – Lukas Eder Mar 18 '12 at 10:27
1

So it seems like you want to simply use github as a cloud backup, right?

  • Clean up your local repo to get rid of errneous changes you made (I'm assuming --stdlayout for the git-svn clone).
  • I suggest creating a new repository (say, mybackup) on github through their web UI.

The commands would be:

$ git reset --hard trunk (clean local tree)
$ git remote add mybackup git@github.com:<username>/mybackup.git (add github remote)
$ git push -u mybackup master (push to github)

Example:

I tried the following in a git-svn -managed repository (foo.git-svn) that I currently have.

$ cd foo.git-svn
$ git reset --hard trunk
$ git svn rebase
$ cd ..
$ mkdir tmp.git && cd tmp.git && git init --bare
$ cd ../foo.git-svn
$ git remote add tmp ../tmp.git
$ git push tmp master

This pushed the master branch of my git-svn repo to a new, purely git repo.

idlethread
  • 1,111
  • 7
  • 16
  • Hmm, that looks like what I need... Can I use the backup solution also on an existing repository (I'd be fine with resetting the repository, I just want to re-use the name) – Lukas Eder Mar 19 '12 at 08:21
  • I'd first try this with a new name, and see if it works. If it does, delete the existing repo on github and recreate it with the existing name. – idlethread Mar 19 '12 at 15:09
  • The key is to make sure that you have a pristine bare repo on github, otherwise your 'git push' will give you trouble. – idlethread Mar 19 '12 at 15:17