简体   繁体   中英

How to git svn fetch + rebase in one operation?

I just discovered that even though the rebase section in git help svn says

This fetches revisions from the SVN parent of the current HEAD and rebases the current (uncommitted to SVN) work against it.

(my emphasis) it doesn't mean that rebase includes a git svn fetch . Naming aside, is there some way to run a single git svn command to do both ?

The reason I want to do this is that I only write on one branch , so I want to rebase that one and I frequently read other branches , so I want to fetch those.

I think you're confusing git rebase and git svn rebase . The former moves commits up to your current HEAD onto some revision you specify, whereas the latter moves your current HEAD onto the tip of the Subversion branch you're on.

git svn rebase does include a git svn fetch --parent , ie it will get any new Subversion commits on the branch you're currently on, but not any Subversion commits from any other branch (contrast with a plain git svn fetch , which fetches from all branches).

I suspect you don't want to do a full git svn fetch when you do a git svn rebase , as it'll mean it'll be much longer before you get a usable working copy. If you want regular git svn fetch es, I'd advise setting up a cron job that'll do the fetch in the background for you.

I'm also a bit surprised to hear that this is actually the way it behaves. But, to answer your question, you just need to define an alias:

git config --global alias.refetch '!git svn fetch && git svn rebase'

Then git refetch should do what you want.

I don't know if this was possible back when this question was asked, but I think that git svn rebase does git svn fetch --parent ; git rebase git-svn git svn fetch --parent ; git rebase git-svn . At least this works for me. It seems that git svn creates git pseudo-branch called git-svn that can be interacted with using git . But this branch cannot be modified by plain git .

If you than wanted full fetch with rebase, you would call git svn fetch ; git rebase git-svn git svn fetch ; git rebase git-svn .

To put it in a language of aliases (as the accepted answer did): git config --global alias.refetch '!git svn fetch && git rebase git-svn'

git pull --rebase

You could also configure it so it rebases by default. Then you can:

git pull

UPDATE:

oops. Need more coffee...

All I can think of is to script what you need..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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