[Insight-developers] Learning from my mistakes (an adventure in git)

Hans Johnson hans-johnson at uiowa.edu
Sat Jul 31 12:35:14 EDT 2010


First let me preface this story:  I am really liking git.  I am now starting
to see the tremendous power that git is going to provide in managing
contributions from multiple developers efficiently.  But as spider man¹s
uncle ben stated  ³With great power comes great responsibility².

This is documentation of how I dug myself out of a big git hole.

Did you ever work yourself into a "git" hole so deep that you want to just
start over?  I did!
While I was fumbling around in trying every nifty git feature I came across,
I ended up with such
a mess that I could not find an elegant way to get out of it.

Here is what I did after getting scared that all the coding work I did was
going to be lost due
my inexperience with git.  I wanted to hit the reset button on git, and
preserve the coding changes I made.

I realize that there are more elegant ways to do this, but those methods
required using tools
that were not above my current skill level.

Problems that I ran into:
1) I forgot to setup the commit hooks, and some of my commits did not pass
that test.
2) I had the wrong e-mail address listed, so I wanted to fix that.
3) I did not understand the branching mechanisms of git very well, so I
ended up with a bit of a mess.
5) My intermediate commits needed to be re-ordered to fit into a more
logical commit structure.

In order to do this, I took my non-logical branches, and created a complete
patch set from them to disk, and then started re-importing the patches in a
organized progression.


Step #1
========================================
mkdir ~/mypatches
git checkout branch1
git format-patch --outputdir ~/mypatches
git checkout branch2
git format-patch --outputdir ~/mypatches
git checkout branch3
git format-patch --outputdir ~/mypatches

#Create patch sets, and then re-apply them as needed.
git fetch origin
git checkout master
git rebase origin/master master




git branch ITKv4.0A (branches off origin/master)
git checkout ITKv4.0A
##=========
%  git apply --check --exclude CMakeLists.txt
/Users/hjohnson/mypatches/0001-Removing-some-outdated-compiler-conditionals.
patch
%  git apply         --exclude CMakeLists.txt
/Users/hjohnson/mypatches/0001-Removing-some-outdated-compiler-conditionals.
patch
### The --exclude CMakeLists.txt was needed because that file was
independantly updated on the master branch prior to patching, and made that
patch unneeded.
%  git apply --check -v --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0003-Second-pass-at-removing-BORLAND-compiler-refs
.patch
%  git apply         -v --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0003-Second-pass-at-removing-BORLAND-compiler-refs
.patch
%  git add -A; git commit
%  git apply --check
/Users/hjohnson/mypatches/0004-Removed-ITK_LEAN_AND_MEAN.patch
%  git apply       
/Users/hjohnson/mypatches/0004-Removed-ITK_LEAN_AND_MEAN.patch
%  git add -A; git commit
%  git apply --check
/Users/hjohnson/mypatches/0005-Unsigned-type-matching-for-ImageDimension.pat
ch
%  git apply       
/Users/hjohnson/mypatches/0005-Unsigned-type-matching-for-ImageDimension.pat
ch
%  git add -A; git commit
%  git apply --check
/Users/hjohnson/mypatches/0006-Removed-__sgi-IRIX-and-SCSL-references.patch
%  git apply       
/Users/hjohnson/mypatches/0006-Removed-__sgi-IRIX-and-SCSL-references.patch
%  git add -A; git commit
%  git apply --check
/Users/hjohnson/mypatches/0007-BUG-11075-Removal-of-SPROC-code.patch
%  git apply       
/Users/hjohnson/mypatches/0007-BUG-11075-Removal-of-SPROC-code.patch
%  git add -A; git commit

##ITKv4.0B (branches off ITKv4.0A)
##=========
%  git apply --check
/Users/hjohnson/mypatches/0006-Remove-itkLegacyMacro-references.patch
%  git apply       
/Users/hjohnson/mypatches/0006-Remove-itkLegacyMacro-references.patch
%  git add -A; git commit
%  git apply --check
/Users/hjohnson/mypatches/0007-Removed-all-legacy-code.patch
%  git apply       
/Users/hjohnson/mypatches/0007-Removed-all-legacy-code.patch
%  git add -A; git commit
%  git apply --check
/Users/hjohnson/mypatches/0002-Removed-Brains2Mask-reader-writer.patch
%  git apply       
/Users/hjohnson/mypatches/0002-Removed-Brains2Mask-reader-writer.patch
%  git add -A; git commit
%  git apply --check
/Users/hjohnson/mypatches/0008-Removed-dual-nature-of-Un-Oriented-Images.pat
ch
%  git apply       
/Users/hjohnson/mypatches/0008-Removed-dual-nature-of-Un-Oriented-Images.pat
ch
%  git add -A; git commit
## Extra whitespace at end of changed lines of code were causing commit
warnings
%  git apply --check --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0009-rm-ITK_USE_CENTERED_PIXEL_COORDINATES_CONSIST
ENTLY.patch
%  git apply         --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0009-rm-ITK_USE_CENTERED_PIXEL_COORDINATES_CONSIST
ENTLY.patch
%  git add -A; git commit
%  git apply --check --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0010-Removed-ITK_USE_DEPRECATED_FAST_MARCHING.patc
h
%  git apply         --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0010-Removed-ITK_USE_DEPRECATED_FAST_MARCHING.patc
h
%  git add -A; git commit
%  git apply --check --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0010-Removed-ITK_USE_DEPRECATED_FAST_MARCHING.patc
h
%  git apply         --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0010-Removed-ITK_USE_DEPRECATED_FAST_MARCHING.patc
h
%  git add -A; git commit
%  git apply --check --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0011-Removed-ITK_USE_DEPRECATED_LEVELSET_INTERPOLA
TION.patch
%  git apply         --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0011-Removed-ITK_USE_DEPRECATED_LEVELSET_INTERPOLA
TION.patch
%  git add -A; git commit
%  git apply --check --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0012-Removed-ITK_USE_REGION_VALIDATION_IN_ITERATOR
S.patch
%  git apply         --ignore-space-change --whitespace=fix
/Users/hjohnson/mypatches/0012-Removed-ITK_USE_REGION_VALIDATION_IN_ITERATOR
S.patch
%  git add -A; git commit

====
Cleanup  -- remove old branches (from local repository, and from my personal
gitHub forked repository).

git push iowaITK :remove_sgi
git push iowaITK :remove_sproc
git push iowaITK :remove_borland
git push iowaITK :ITK_LEGACY_REMOVE
git push iowaITK :REMOVE_ORIENTED_IMAGE
git push iowaITK ITKv4.0A
git push iowaITK ITKv4.0B



I hope this is useful to somebody.

Hans

-- 
Hans J. Johnson, Ph.D.
Assistant Professor
200 Hawkins Drive
T205 BT, The University of Iowa
Iowa City, IA 52242

hans-johnson at uiowa.edu
PHONE: 319 353 8587

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20100731/5963b050/attachment.htm>


More information about the Insight-developers mailing list