Search code examples
gitsvnresetrebaserevert

How to reset a Git repository and check out sources from SVN afresh?


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"

Solution

  • 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.