How to show which commits Git-SVN will push or merge

My previous post explains how to show which commits Git will push or merge. This is a follow-up explaining how to achieve the same with Git-SVN.

These are the aliases you need in your Git configuration file (e.g. C:cygwinhome<user>.gitconfig or <project>/.git/config). The explanation is below.

[alias]
    # -M                 Detect and report renames for each commit.
    # --name-status      Show only names and status of changed files.
    # --abbrev-commit    Instead of showing the full 40-byte hexadecimal commit object name, show only a partial prefix.
    l = log -M --name-status --abbrev-commit

    # --oneline          This is a shorthand for &amp;quot;--pretty=oneline --abbrev-commit&amp;quot; used together.
    l1 = log --oneline

    # log commits-to-push
    lctp  = &amp;quot;!REMOTE_BRANCH=$(git svn info --url | gawk -F'/' '{print $NF}'); 
            COMMAND=&amp;quot;git l remotes/$REMOTE_BRANCH..HEAD&amp;quot;; 
            echo $COMMAND; 
            $COMMAND&amp;quot;
    lctp1 = &amp;quot;!REMOTE_BRANCH=$(git svn info --url | gawk -F'/' '{print $NF}'); 
            COMMAND=&amp;quot;git l1 remotes/$REMOTE_BRANCH..HEAD&amp;quot;; 
            echo $COMMAND; 
            $COMMAND&amp;quot;

    # log commits-to-merge
    # do not forget to execute &amp;quot;git svn fetch&amp;quot; first
    lctm  = &amp;quot;!REMOTE_BRANCH=$(git svn info --url | gawk -F'/' '{print $NF}'); 
            COMMAND=&amp;quot;git l HEAD..remotes/$REMOTE_BRANCH&amp;quot;; 
            echo $COMMAND; 
            $COMMAND&amp;quot;
    lctm1 = &amp;quot;!REMOTE_BRANCH=$(git svn info --url | gawk -F'/' '{print $NF}'); 
            COMMAND=&amp;quot;git l1 HEAD..remotes/$REMOTE_BRANCH&amp;quot;; 
            echo $COMMAND; 
            $COMMAND&amp;quot;


I recommend reading my previous post because the explanation below is somewhat more condensed.

The very good book Pro Git, chapter 8-1, explains that after cloning your Subversion repository into a local Git repository, you will have something similar to the following:

$ git branch -a
  master
  remotes/issue1
  remotes/trunk

To create a local working branch for the remote issue1 branch, you can use:

$ git branch my-issue1 remotes/issue1

$ git branch -a
  master
  my-issue1
  remotes/issue1
  remotes/trunk

The following command shows you any commits in your current branch (HEAD) that are not in trunk on the remote server:

$ git log trunk..HEAD

If you are on the my-issue1 branch you can execute:

$ git log issue1..HEAD

Note that if your local branch has the same name as your remote branch, you must prefix the remote branch with remotes/:

$ git log remotes/issue1..HEAD

If you want to keep the current branch up to date and preview what you are about to merge in, you can reverse the two sides of the double dot syntax:

$ git log HEAD..trunk

$ git log HEAD..issue1
 
$ git log HEAD..remotes/issue1

Of course, for this to work you must first execute git svn fetch.

To automatically get the correct branch name used by the SVN server, you can use the SVN server information command git svn info. To output only the value of the URL: field, you must use git svn info --url:

$ git svn info --url
https://&lt;domain&gt;/svn/&lt;project&gt;/trunk

For local branch my-issue1, you get:

$ git svn info --url
https://&lt;domain&gt;/svn/&lt;project&gt;/branches/issue1

We will use (g)awk to get the last part of the SVN URL:

$ git checkout master
Switched to branch 'master'

$ git svn info --url | gawk -F'/' '{print $NF}'
trunk

$ git checkout my-issue1
Switched to branch 'my-issue1'

$ git svn info --url | gawk -F'/' '{print $NF}'
issue1

If you put all this together in an alias, you get (without character escaping):

[alias]
    # log commits-to-push
    lctp  = &amp;quot;!REMOTE_BRANCH=$(git svn info --url | gawk -F'/' '{print $NF}');
            COMMAND=&amp;quot;git l remotes/$REMOTE_BRANCH..HEAD&amp;quot;;
            echo $COMMAND;
            $COMMAND&amp;quot;

    # log commits-to-merge
    # do not forget to execute &amp;quot;git svn fetch&amp;quot; first
    lctm  = &amp;quot;!REMOTE_BRANCH=$(git svn info --url | gawk -F'/' '{print $NF}');
            COMMAND=&amp;quot;git l HEAD..remotes/$REMOTE_BRANCH&amp;quot;;
            echo $COMMAND;
            $COMMAND&amp;quot;

$REMOTE_BRANCH becomes trunk or issue1;
git l remotes/$REMOTE_BRANCH..HEAD becomes
    git l remotes/trunk..HEAD or
    git l remotes/issue1..HEAD.

You can use the aliases like this:

$ git commit -m &amp;quot;...&amp;quot;
 
$ git lctp
 
$ git svn dcommit
 
...
 
$ git svn fetch
 
$ git lctm

$ git svn rebase --local

Comments are closed.