Is there a way with git-svn to determine how many commits ahead or behind I am?
Thanks!
Is there a way with git-svn to determine how many commits ahead or behind I am?
Thanks!
Not directly. What you can do, though, is find out how far ahead and/or behind you are from the local copy of the Subversion repository.
So start with git svn fetch
to bring your local repository up-to-date, and go from there.
To find out how many commits there are in the branch you're currently on, but which haven't been committed to the Subversion server, there's a whole bunch of tricks, but the most obvious one is to run git svn dcommit --dry-run
, and see how many commits are listed to be pushed to Subversion.
Short version: run git svn dcommit --dry-run | grep diff-tree | wc -l
.
To work out how many commits are in the Subversion repository, but not in the branch you're working on, you need to first work out or know the name of the Subversion branch you're working from. You can probably work this out from the first line of git svn dcommit --dry-run
, or from git log -1 --grep git-svn-id
.
Say your branch is master
, and the parent Subversion branch is remotes/svn/trunk
. You can then run git svn rev-list master..remotes/svn/trunk | wc -l
to count all the commits that are in the remote trunk and not in your branch.
As an alternative to all the above, when you create a branch, specify it as tracking a Subversion branch. For example, when I create a local branch based on the remote trunk, I create it as follows:
git checkout -b new-branch-name -t remotes/svn/trunk
Now, whenever I do git status
or git checkout new-branch-name
, the output will include a line telling me just how far ahead or behind each branch is relative to the other.
For a branch that already exists, you can set it up to track a Subversion branch as below:
git branch --set-upstream existing-branch remotes/svn/trunk
In git >= 1.9, there seems to be a bug that prevents using --set-upstream/--set-upstream-to
It doesn't work for me either in git 2.23.0
The workaround is to modify the .gitconfig manually : how-to-set-upstream-branch-in-git-svn