git svn-status: “svn status” remake for Git 2009-03-22

I’ve been playing around with commands to produce an exact clone of svn status for Git.

git status would have said this about my repository:

$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: bla3 # new file: bla4 # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: bla2 # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # bla

With the svn status remake I get:

$ git svn-status ? bla M bla2 D bla3 M bla4

This is the command I came up with:

{ \ git ls-files -o --directory -t ; \ git status | grep --color=never 'deleted: ' | sed 's|^.*deleted: ||' | sed 's|^|D |' ; \ git ls-files -m -s | awk '{print $NF}' | sort -u | sed 's|^|M |' ; \ } \ | sort -k 2 \ | sed 's|^\(.\) *|\1 |'

Some notes:

  • I’m quite sure a much easier command is possible. If you know how please comment below or mail me.
  • git ls-files -d didn’t list the deleted files for me. Maybe I hit a bug, not sure yet. Git 1.6.2 here.

You can register the alias through:

git config alias.svn-status \!"\ { \ git ls-files -o --directory -t ; \ git status | grep --color=never 'deleted: ' | sed 's|^.*deleted: ||' | sed 's|^|D |' ; \ git ls-files -m -s | awk '{print \$NF}' | sort -u | sed 's|^|M |' ; \ } \ | sort -k 2 \ | sed 's|^\\(.\\) *|\\1 |'"

Looking forward to your simplified replacements.

sping March 22nd, 2009

PS: Found something interesting about git ls-files -d:

[BUG?] ls-files -d does not show files removed using ‘git rm’

eyebex March 23rd, 2009

How about this:

$ git diff –name-status

eyebex March 23rd, 2009

Sorry, you need two dashes (it seems it was stripped because I did not embed it into a code section):

$ git diff –-name-status

sping March 23rd, 2009

Interesting. It seems to show a subset of svn-status only, though.

Shane June 23rd, 2009

Nice. I was looking for something just like this. This blog post is trying to do the same thing and does so using some different tools. Have a look.

Shane July 9th, 2009

I ran into a few snags, and I updated it. The only thing that’s different about this command from ‘svn status’ is the ordering is all ‘?’ files first then all the modifications, but as it is I actually like that way better. Here’s what I have:

svn-status = "! git ls-files --exclude-per-directory=.gitignore --exclude-from=.git/info/exclude --exclude-from=$HOME/.gitignore --others -t | sed 's| |\t|'; git diff HEAD --name-status "

Leave a Reply

You must be logged in to post a comment.