[Insight-developers] some useful git commands for ITK

Brad King brad.king at kitware.com
Tue Aug 3 10:22:08 EDT 2010


On 08/03/2010 06:10 AM, Gaëtan Lehmann wrote:
> I have a problem on solaris, where /bin/sh is actually sh, not bash.
> Some expressions like $() doesn't seem to be supported.

That's interesting because Git's implementation uses $() all over the
place in shell scripts.  I think they configure the shebang line at
build time.  What does the "git-submodule" script in your git install
use for its shebang line?  Note that it uses $() right near the top.

It's really a shame that ancient shell creators did not use the $()
syntax.  It is *much* easier to write and read than ``.

> As a quick fix, I've changed the shell bang in
> 
>    #!/usr/bin/env bash
> 
> which should work almost everywhere.
> 
> Can you commit that in the hooks?

Sure, but first I'm interested in the above answer.

> if they are local uncommitted changes, the following sequence may be  
> required:
> 
> git stash
> git pull --rebase
> git stash pop

Yes.

>> Good.  You can also do
>>
>>  git log --follow -- a_file
>>
>> to follow its log through renames.
> 
> nice - git is even capable to follow the files which were moved from  
> Code/Review to Code/BasicFilters with cvs :-)

Well, it can only follow renames that were done by removing the old
name and adding the new name in a single commit.  Otherwise it just
sees the change as an addition of a new file in one commit and the
removal of the old file in another commit.

Take itkBinaryProjectionImageFilter.h for example:

$ git log add8e462 --follow -- Code/BasicFilters/itkBinaryProjectionImageFilter.h
commit 2642282b44568156eaa3f965fbdb1d2c110ebcd6
Author: Bill Lorensen <bill.lorensen at gmail.com>
Date:   Thu Feb 7 23:53:09 2008 -0500

    ENH: Moving Projection filters from Review to BasicFilters.

$ git log add8e462 --stat -- Code/BasicFilters/itkBinaryProjectionImageFilter.h Code/Review/itkBinaryProjectionImageFilter.h
commit add8e4620cfdc4fdb9f7a71e94e902b767905ce7
Author: Bill Lorensen <bill.lorensen at gmail.com>
Date:   Wed Feb 13 23:21:32 2008 -0500

    ENH: Moving Projection filters from Review to BasicFilters.

 Code/Review/itkBinaryProjectionImageFilter.h |  203 --------------------------
 1 files changed, 0 insertions(+), 203 deletions(-)

commit 2642282b44568156eaa3f965fbdb1d2c110ebcd6
Author: Bill Lorensen <bill.lorensen at gmail.com>
Date:   Thu Feb 7 23:53:09 2008 -0500

    ENH: Moving Projection filters from Review to BasicFilters.

 Code/BasicFilters/itkBinaryProjectionImageFilter.h |  205 ++++++++++++++++++++
 1 files changed, 205 insertions(+), 0 deletions(-)

However, "git blame" is able to follow the content *copy* between
the files.  We have to use two "-C" options to ask it to try extra
hard to find copies because the source of the copy was not modified
in the same commit as the new file was added:

$ git blame -M -C -C -- Code/BasicFilters/itkBinaryProjectionImageFilter.h
...
4e61459f Code/Review/itkBinaryProjectionImageFilter.h                  (Andinet Enquobahrie 2007-01-16 00:15:33 -0500  17) #ifndef __itkBinaryProjectionImageFilter_h
4e61459f Code/Review/itkBinaryProjectionImageFilter.h                  (Andinet Enquobahrie 2007-01-16 00:15:33 -0500  18) #define __itkBinaryProjectionImageFilter_h
4e61459f Code/Review/itkBinaryProjectionImageFilter.h                  (Andinet Enquobahrie 2007-01-16 00:15:33 -0500  19)
4e61459f Code/Review/itkBinaryProjectionImageFilter.h                  (Andinet Enquobahrie 2007-01-16 00:15:33 -0500  20) #include "itkProjectionImageFilter.h"
4e61459f Code/Review/itkBinaryProjectionImageFilter.h                  (Andinet Enquobahrie 2007-01-16 00:15:33 -0500  21) #include "itkNumericTraits.h"
bf1ac4b7 Code/Review/itkBinaryProjectionImageFilter.h                  (Andinet Enquobahrie 2007-01-23 12:41:01 -0500  22) #include "itkConceptChecking.h"
4e61459f Code/Review/itkBinaryProjectionImageFilter.h                  (Andinet Enquobahrie 2007-01-16 00:15:33 -0500  23)
...

-Brad


More information about the Insight-developers mailing list