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.

The git svn-status: “svn status” remake for Git by Sebastian Pipping, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.







PS: Found something interesting about git ls-files -d:
[BUG?] ls-files -d does not show files removed using ‘git rm’
http://kerneltrap.org/index.php?q=mailarchive/git/2008/8/22/3040964/thread
How about this:
$ git diff –name-status
Sorry, you need two dashes (it seems it was stripped because I did not embed it into a code section):
$ git diff –-name-statusInteresting. It seems to show a subset of svn-status only, though.
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.
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 "