如何在git-svn中设置上游分支? [英] How to set upstream branch in git-svn?
问题描述
在通常的git仓库上工作时,本地分支通常会跟踪相应的远程上游分支.通过这种方式,我可以轻松地看到自己是在上游分支的前面还是后面,以及是否需要推动或拉动它们以使其同步.同样,我的提示会立即显示此状态,这非常方便.
While working on a usual git repository a local branch usually tracks a corresponding remote upstream branch. This way I can easily see, whether I am ahead or behind of my upstream branch and therefore if I need to push or pull to bring them in sync. Also my prompt immediately shows this state, which is very convenient.
现在,我正在使用git-svn
处理SVN存储库.我将--prefix=svn
用于克隆,因此git branch -r
将svn/trunk
列为远程分支,但是(尽管git svn rebase
正常工作,但没有问题)它没有配置为我的主分支的上游分支.
Now I am working on a SVN repository using git-svn
. I used --prefix=svn
for the clone, therefore git branch -r
lists svn/trunk
as a remote branch, but (although git svn rebase
works without problems) it is not configured as an upstream branch for my master branch.
我尝试手动设置跟踪信息,但失败:
I tried to set the tracking information manually but it failed:
$ git branch -r
svn/trunk
$ git branch --set-upstream-to=svn/trunk
fatal: Cannot setup tracking information; starting point 'svn/trunk' is not a branch.
有什么方法可以跟踪svn上游分支吗?
Is there some way to track an svn upstream branch?
是否还有其他简单的方法可以知道我在该分支机构之前还是之后? (目前,我唯一了解的就是gitk --all
.)
Is there some other easy way to know whether I am ahead or behind to that branch? (Looking at gitk --all
is currently the only way I am aware of.)
还有什么方法可以使我的提示(bash __git_ps1
)显示该信息吗?
Is there even some way to make my (bash __git_ps1
) prompt show that information?
$ git --version
git version 1.9.0.msysgit.0
推荐答案
这似乎是git 1.9中引入的错误,因为--set-upstream-to
完全按照您提到的方式工作.
And strace
显示上游分支ref的正确定位和读取,但是由于某些原因而被忽略.
This seems to be a bug introduced in git 1.9, since --set-upstream-to
worked before exactly as you mention.
And strace
displays correct locating and reading of the upstream branch ref, then however it's ignored for some reason.
我针对此问题的解决方法是
My workaround for this issue is manual editing of .git/config
:
$ cat >> .git/config << EOF
[branch "master"]
remote = .
merge = refs/svn/trunk
rebase = true
EOF
-应该等同于:
git branch --set-upstream-to=svn/trunk master
&& git config branch.master.rebase true
(无论如何,您都希望使用svn)
&& git config branch.master.rebase true
(which you'll want with svn anyway)
-但不是,因为有错误! 当然,我的refs/svn/trunk
是分支!"您说,然后直接编辑配置(只需轻轻一点).
— but is not, because of a bug! "Of course my refs/svn/trunk
is a branch!" you say, and edit the config directly (with just a little bit of gentle force).
您的svn干线在git中的名称可能不同,具体取决于您克隆存储库的方式(-s
,-T
,--prefix
到git svn clone
的选项).只需执行git branch -avv
并找到正确的一个即可.例如,一个可能的名称是refs/remotes/git-svn
;或如上所述的refs/svn/trunk
;甚至其他东西.
Your svn trunk could be named differently in git depending on how you cloned the repo (-s
, -T
, --prefix
options to git svn clone
). Just do a git branch -avv
and find the correct one. For example, one possible name is refs/remotes/git-svn
; or refs/svn/trunk
as above; or even something else.
我仍然在git version 2.1.4
上重现此内容.任何人都可以提交错误报告吗?
I still reproduce this on git version 2.1.4
. Anyone to bother file a bug report?
这篇关于如何在git-svn中设置上游分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!