<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>t+1 &#187; git</title>
	<atom:link href="http://blog.tplus1.com/index.php/category/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tplus1.com</link>
	<description>Programming, gardening, economics, life in Cleveland Heights</description>
	<lastBuildDate>Sat, 07 Jan 2012 21:12:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Undo a fast-forward git merge</title>
		<link>http://blog.tplus1.com/index.php/2011/09/23/undo-a-fast-forward-git-merge/</link>
		<comments>http://blog.tplus1.com/index.php/2011/09/23/undo-a-fast-forward-git-merge/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 14:16:51 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://blog.tplus1.com/?p=721</guid>
		<description><![CDATA[A friend has a fork of my project and sent me a pull-request.  Without doing any eyeballing at all, I did this:

$ git fetch XXX
$ git merge XXX/master

Git ran a fast-forward merge and now all those commits are in my code.  Then I ran some tests and KABOOM.
After spending a while digging around [...]]]></description>
			<content:encoded><![CDATA[<p>A friend has a fork of my project and sent me a pull-request.  Without doing any eyeballing at all, I did this:<br />
<pre><code>
$ git fetch XXX
$ git merge XXX/master
</code></pre><br />
Git ran a fast-forward merge and now all those commits are in my code.  Then I ran some tests and KABOOM.</p>
<p>After spending a while digging around and seeing just how much needed to be fixed, I decided that it would be better to just send an email with the test errors back to my friend rather than try to fix them myself.  I got my own work to do, after all.</p>
<p>So I sent the email, but now I had a git checkout with all those commits.</p>
<p>And since this was a fast-forward merge, git didn&#8217;t create a commit for the merge.</p>
<p>Incidentally, today I learned that you can force git to make an explicit commit for fast-forward merges like this:<br />
<pre><code>
$ git merge --no-ff XXX/master
</code></pre></p>
<p>I went to #git on irc.freenode.org, where I always go, and I explained the situation, and then was told to do these commands:<br />
<pre><code>
$ git reflog show master
$ git reset --keep master@{1}
</code></pre></p>
<p>And it worked!  All the foreign commits are now gone.</p>
<p>But what just happened?</p>
<p>I&#8217;m not absolutely certain, but it seems like the git reflog show master command shows the changes applied to HEAD over time.  This is what the top lines showed for me:<br />
<pre><code>
cce8252 master@{0}: merge XXX/master: Fast-forward
08c8f50 master@{1}: commit: Cleaning up the my-account pages
5526212 master@{2}: commit: Deleted a handler that was never getting used
</code></pre></p>
<p>This is different than git log.  This is talking about the state of my local master branch over time.  </p>
<p>Then, the next command git reset &#8211;keep master@{1} is telling git to reset the checkout to look like what master looked like one state in the past.</p>
<p>Like I said, I&#8217;m still not sure I understand this, but I plan to study it more.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tplus1.com/index.php/2011/09/23/undo-a-fast-forward-git-merge/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Some notes from when I start using git</title>
		<link>http://blog.tplus1.com/index.php/2010/12/18/some-notes-from-when-i-start-using-git/</link>
		<comments>http://blog.tplus1.com/index.php/2010/12/18/some-notes-from-when-i-start-using-git/#comments</comments>
		<pubDate>Sat, 18 Dec 2010 14:48:41 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://blog.tplus1.com/?p=668</guid>
		<description><![CDATA[When I switched to git from subversion at my old business, I stored notes on how to do certain tasks.  I&#8217;m pasting it below.  Maybe some of this will help you out.
If you know a better way to do these tricks, please let me now.

My git diary
============

.. contents::

Slowly learning how to use git.

Typical [...]]]></description>
			<content:encoded><![CDATA[<p>When I switched to git from subversion at my old business, I stored notes on how to do certain tasks.  I&#8217;m pasting it below.  Maybe some of this will help you out.</p>
<p>If you know a better way to do these tricks, please let me now.<br />
<pre><code>
My git diary
============

.. contents::

Slowly learning how to use git.

Typical upgrade flow
--------------------

I just committed a bunch of code and I want to see what the diffs were,
so I ran this::

&nbsp;&nbsp;&nbsp;&nbsp;$ git diff HEAD^

My production server runs branch 3.5.1 of my software.&nbsp;&nbsp;I want to start
work on a scary new feature that may take a long time, so I made a new
branch called 3.5.2 in my local sandbox::

&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout -b 3.5.2

Now I can commit all my intermediate stuff in here.

Somebody found a bug in the production site (running 3.5.1) so I switch
to my 3.5.1 checkout::

&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout 3.5.1
&nbsp;&nbsp;&nbsp;&nbsp;$ vi # fixing the problem
&nbsp;&nbsp;&nbsp;&nbsp;$ git commit -a -m &quot;Fixed the prod bug&quot;
&nbsp;&nbsp;&nbsp;&nbsp;$ git push origin 3.5.1

That last line sends my local commits to my remote bare repository.
That remote bare repository is on a box with an SSH server and RAID
storage.

Then I connect to the production box and pull down the most recent
changes::

&nbsp;&nbsp;&nbsp;&nbsp;$ ssh prod
&nbsp;&nbsp;&nbsp;&nbsp;matt@prod$ cd where-the-repo-is
&nbsp;&nbsp;&nbsp;&nbsp;matt@prod$ git pull origin 3.5.1
&nbsp;&nbsp;&nbsp;&nbsp;matt@prod$ restart-everything

That restart-everything command is a homemade script that does just what
you think it does.

Now back in my dev sandbox, I want to pull the bug fix from 3.5.1 into
my 3.5.2 branch.&nbsp;&nbsp;So I do it like this::

&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout 3.5.2
&nbsp;&nbsp;&nbsp;&nbsp;$ git pull . 3.5.1

And now my 3.5.2 branch has that code in it.&nbsp;&nbsp;Hurray!&nbsp;&nbsp;Understand that
the dot (.) in git pull . 3.5.1 means that git should retrieve code from
this repository, not the fancypants remote one.

Pulling stuff
-------------

When I run::

&nbsp;&nbsp;&nbsp;&nbsp;$ git pull origin 3.5.1

That means to pull from the origin&#039;s 3.5.1 branch into whatever branch I
currently have checked out.

A typical day
-------------

I have two branches, an experimental branch and a public branch.
The production server used by customer runs the public branch.

Usually I work in my development branch.&nbsp;&nbsp;Sometimes I have to do some
code into production so this is how I do it::

&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout stable # switch my local copy to the stable branch.
&nbsp;&nbsp;&nbsp;&nbsp;$ git pull origin stable # update local copy, just in case.
&nbsp;&nbsp;&nbsp;&nbsp;$ vi blah.py # do the bug fixes.
&nbsp;&nbsp;&nbsp;&nbsp;$ git commit -a -m &quot;Notes about bug fixes&quot;
&nbsp;&nbsp;&nbsp;&nbsp;$ git push origin # This is my deploy system.
&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout dev # Go back to my development branch.
&nbsp;&nbsp;&nbsp;&nbsp;$ git pull origin stable # merge in that bug fix.

So far, this works well.&nbsp;&nbsp;I did something similar with SVN, and it also
worked fine.&nbsp;&nbsp;But git is way better at safely merging and it is much
faster.

Undo changes to a single file
-----------------------------

I typically edit a dozen files and then figure out that I want to undo
some stuff.&nbsp;&nbsp;If I did::

&nbsp;&nbsp;&nbsp;&nbsp;$ git reset --hard

Then my whole working copy would be destroyed.&nbsp;&nbsp;Usually, I just want to
do something like revert one file.&nbsp;&nbsp;So this is how::

&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout that/particular/file

That deletes my working-copy changes just there.&nbsp;&nbsp;Everything else is
left as-is.

How to submit patches by email
------------------------------

I cloned the ditz project and tweaked the code, and I wanted to submit a
patch, so this is what they told me to do::

&nbsp;&nbsp;&nbsp;&nbsp;For this type of thing, it&#039;s &quot;very simple&quot;. git commit -a, add a
&nbsp;&nbsp;&nbsp;&nbsp;one-line description followed by a blank line and more commentary, and
&nbsp;&nbsp;&nbsp;&nbsp;then git format-patch HEAD^.

When I ran git format-patch HEAD^, that produced a file on my local
machine that had a pretty formatted patch.&nbsp;&nbsp;Then I emailed that patch to
the list with some text.

How to branch from a remote repository
--------------------------------------

This is what somebody in the #git room told me to do, since I use a
remote bare repository::

&nbsp;&nbsp;&nbsp;&nbsp;$ git fetch origin
&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout -b newbranch origin/original

Here&#039;s another person&#039;s opinion::

&nbsp;&nbsp; $ git fetch &amp;&amp; git checkout --track -b mynewbranchagain remotename/mynewbranch

Set the remote branch
---------------------

Normally I have to pull from my remote repo and specify the branch I
want to pull in like this::

&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout experimental
&nbsp;&nbsp;&nbsp;&nbsp;$ git pull origin experimental

It is possible to associate my local branch of experimental with that
remote branch of experimental like this::

&nbsp;&nbsp;&nbsp;&nbsp;$ git config --add branch.experimental.remote origin
&nbsp;&nbsp;&nbsp;&nbsp;$ git config --add branch.experimental.merge experimental

And now I can run::

&nbsp;&nbsp;&nbsp;&nbsp;$ git pull origin

without specifying the remote branch.&nbsp;&nbsp;In fact this works too::

&nbsp;&nbsp;&nbsp;&nbsp;$ git pull

Compare one file across two local branches
------------------------------------------

I want to look at a diff of x.py in my public branch vs my experimental
branch, so this is what I did::

&nbsp;&nbsp;&nbsp;&nbsp;$ git diff public experimental -- x.py

I can see everything different between the two branches like this::

&nbsp;&nbsp;&nbsp;&nbsp;$ git diff public experimental

Break up a whole bunch of changes into different commits
--------------------------------------------------------

I&#039;m irresponsible about committing after each conceptual unit of work.
Lots of time, I&#039;ll edit a file to fix one bug, then while I&#039;m in there,
I&#039;ll edit some other code because I see a better way to do something
else.&nbsp;&nbsp;Then I&#039;ll maybe add a few doctests to a completely different
section just because I want to.

After a few hours, typically inside of the same file, I have edits
related to multiple separate tasks.

Before I commit my changes, I run::

&nbsp;&nbsp;&nbsp;&nbsp;$ git add -p frob.py

Which walks through all the changes in that file and asks me if I want
to stage each one.&nbsp;&nbsp;In the first pass, I stage all the hunks related to
the first issue.&nbsp;&nbsp;Then I commit those changes.&nbsp;&nbsp;Then I rerun git add -p
frob.py again and march through the file for the next the second issue.

Keep in mind that I committed my changes after the first pass, so when I
go through the file the second time, I won&#039;t get prompted for those
changes.

This is one of those git features that you just couldn&#039;t do with svn.

Find the commits in branch A that are not in branch B
-----------------------------------------------------

Sometimes I&#039;ll patch a production bug in my production branch and then I
will forget to merge it into the development branch.&nbsp;&nbsp;This is how I can
check for that::

&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout production_branch
&nbsp;&nbsp;&nbsp;&nbsp;$ git cherry dev_branch

This will spit out a list of commits that are in production_branch but
not in dev_branch.

It will not return any commits made to dev_branch but not in
production_branch.

See a file as of a point in time
--------------------------------

Looking at a commit shows the changes.&nbsp;&nbsp;Sometimes I want to see the file
itself.

Here&#039;s how to look at foo.py as of two commits ago::

&nbsp;&nbsp;&nbsp;&nbsp;$ git show HEAD^^:b/foo.py

Here&#039;s how to see what foo.py looked as of a particular commit::

&nbsp;&nbsp;&nbsp;&nbsp;$ git show bf51ebdbc:b/foo.py

b/foo.py is the path to the foo.py from the top of the repository.&nbsp;&nbsp;I&#039;m
not certain, but I don&#039;t think the current working directory matters.

Copy a file from one branch to another
--------------------------------------

I committed a file into one branch then checked out a new branch.&nbsp;&nbsp;This
is how I copied that file into the new branch WITHOUT merging it in::

&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout newbranch # 1
&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout otherbranch foo.py # 2

Step 1 moves me into the newbranch.&nbsp;&nbsp;Step 2 gets me a copy of the file
foo.py from otherbranch and saves it into this branch named newbranch.

See a file in a different branch
--------------------------------

After I checkout the maxhenry branch I want to see the version of
printable.kid in the mayfield branch::

&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout maxhenry
&nbsp;&nbsp;&nbsp;&nbsp;$ git show mayfield:bazman/bazman/templates/printable/printable.kid

Set a file to an old version of itself
--------------------------------------

Sometimes I want to get the version of a file as of a certain commit and
check that in.&nbsp;&nbsp;There are lots of ways to do this, including using git
revert or git reset, but I&#039;ve had good luck with this approach::

&nbsp;&nbsp;&nbsp;&nbsp;$ git log # Use this to find the commit you want.

&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout ac778cbb5517e1aeef446c9a8a1092eef81717fa:repo-top/a/foo.py

After you run this, the index will have this old copy queued up to be
commited. You can use git diff --cached to see the changes.

Create a new branch on the remote repo
--------------------------------------

We just pushed the branch **mollusk** up to production, so now it is
time to create a new branch named **nosehair**::

&nbsp;&nbsp;&nbsp;&nbsp;$ git branch nosehair # creates the new branch
&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout nosehair # switches to the new branch
&nbsp;&nbsp;&nbsp;&nbsp;$ git push origin nosehair # pushes it up to origin

Switch to a new branch that already exists on a remote repo
-----------------------------------------------------------

After somebody else already created the branch nosehair, and pushed it
up to the remote repository, here&#039;s how to switch to work on the
nosehair branch::

&nbsp;&nbsp;&nbsp;&nbsp;$ git fetch origin
&nbsp;&nbsp;&nbsp;&nbsp;$ git branch -a # make sure origin/nosehair exists!
&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout -b nosehair origin/nosehair

Search through commit messages
------------------------------

This is how I found all commits that had a commit message that included
the word CCPL::

&nbsp;&nbsp;&nbsp;&nbsp;$ git log --grep=CCPL

This is how I limited it to just my (Matt&#039;s) commits for CCPL work::

&nbsp;&nbsp;&nbsp;&nbsp;$ git log --grep=CCPL --author=matt --all-match

Without the --all-match option, you&#039;ll see all commits by matt or that
have CCPL in the commit message.

</code></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tplus1.com/index.php/2010/12/18/some-notes-from-when-i-start-using-git/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>git cherry is neat</title>
		<link>http://blog.tplus1.com/index.php/2009/01/29/git-cherry-is-neat/</link>
		<comments>http://blog.tplus1.com/index.php/2009/01/29/git-cherry-is-neat/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 18:51:51 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://blog.tplus1.com/?p=270</guid>
		<description><![CDATA[Sometimes I&#8217;ll patch a production bug in my production branch and then I will forget to merge that commit into the development branch.  This is how I can check for that:

&#160;&#160;&#160;&#160;$ git checkout production_branch
&#160;&#160;&#160;&#160;$ git cherry dev_branch

This will spit out a list of commits that are in production_branch but not in dev_branch.  It [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I&#8217;ll patch a production bug in my production branch and then I will forget to merge that commit into the development branch.  This is how I can check for that:<br />
<pre><code>
&nbsp;&nbsp;&nbsp;&nbsp;$ git checkout production_branch
&nbsp;&nbsp;&nbsp;&nbsp;$ git cherry dev_branch
</code></pre><br />
This will spit out a list of commits that are in production_branch but not in dev_branch.  It will not return any commits made to dev_branch but not in production_branch.  It is not the same as a diff of the two branches either.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tplus1.com/index.php/2009/01/29/git-cherry-is-neat/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Break up changes into different commits with git add -p</title>
		<link>http://blog.tplus1.com/index.php/2008/10/31/break-up-changes-into-different-commits-with-git-add-p/</link>
		<comments>http://blog.tplus1.com/index.php/2008/10/31/break-up-changes-into-different-commits-with-git-add-p/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 16:10:37 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://blog.tplus1.com/?p=240</guid>
		<description><![CDATA[This guy&#8217;s post led to this one.
I&#8217;m irresponsible about committing after each conceptual unit of work.  Lots of time, I&#8217;ll edit a file to fix one bug, then while I&#8217;m in there, I&#8217;ll edit some other code because I see a better way to do something else.  Then maybe I&#8217;ll add a few [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://all-thing.net/2008/10/some-git-fu.html">This guy&#8217;s post</a> led to this one.</p>
<p>I&#8217;m irresponsible about committing after each conceptual unit of work.  Lots of time, I&#8217;ll edit a file to fix one bug, then while I&#8217;m in there, I&#8217;ll edit some other code because I see a better way to do something else.  Then maybe I&#8217;ll add a few doctests to a completely different section because I feel like it.</p>
<p>After a few hours, I have edits in a single file that are related to multiple separate tasks.  So back when I used svn, I would commit it with a message like &#8220;Fixed topics A, B, C&#8221;.  Or I would say &#8220;Fixed A and a bunch of other stuff&#8221;.</p>
<p>Now with git, before I commit my changes, I run:<br />
<pre><code>
$ git add -p frob.py
</code></pre><br />
Then git opens up an interactive session that walks through all the changes in that file and asks me if I want to stage each one.  It is also possible to look at every change across a repository if you want to &#8212; don&#8217;t specify the file or files you want to see.</p>
<p>In the first pass, I stage all the hunks related to the first issue.  Then I commit those changes.  Then I repeat the process and stage chunks related to the next issue.</p>
<p>Keep in mind that I committed my changes after the first pass, so when I go through the file the second time, I won&#8217;t get prompted for those changes.</p>
<h2>A real-world example</h2>
<p>I&#8217;ve got two edits in mkinstall.py.  One is a change to the list of files I want to ignore, and the other edit is a silly stylistic change.  I want to commit them separately.<br />
<pre><code>
$ git diff mkinstall.py 
diff --git a/mkinstall.py b/mkinstall.py
index 4c6bb4e..2cb43de 100644
--- a/mkinstall.py
+++ b/mkinstall.py
@@ -17,7 +17,8 @@ Otherwise, I&#039;ll add a symlink.
 import os, shutil
 </code></pre><pre><code>
 # Anything you want to skip:
-skip_us = [&quot;mkinstall.py&quot;, &quot;.svn&quot;, &quot;_vimrc&quot;]
+skip_us = [&quot;mkinstall.py&quot;, &quot;.svn&quot;, &quot;_vimrc&quot;, &quot;diffwrap.sh&quot;, &quot;lib&quot;,
+&nbsp;&nbsp;&nbsp;&nbsp;&quot;lynx_bookmarks.html&quot;, &quot;ipythonrc-matt&quot;, &quot;.git&quot;]
</code></pre><pre><code> 
 # Anything you want to copy rather than symlink to: 
 copy_us = [&quot;.vim&quot;]
@@ -60,7 +61,8 @@ for thing in copy_us:
&nbsp;&nbsp;&nbsp;&nbsp; if os.path.islink(homefile):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;A symbolic link to %s exists already, so I&#039;m not going to copy over it.&quot; % homefile
</code></pre><pre><code>
-&nbsp;&nbsp;&nbsp;&nbsp;elif os.path.exists(homefile): continue
+&nbsp;&nbsp;&nbsp;&nbsp;elif os.path.exists(homefile): 
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue
</code></pre><pre><code>
&nbsp;&nbsp;&nbsp;&nbsp; else:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; svnfile = os.path.join(svnpath, thing)
</code></pre>   </p>
<p>This is what happens when I run git add -p:<br />
<pre><code>
$ git add -p mkinstall.py 
diff --git a/mkinstall.py b/mkinstall.py
index 4c6bb4e..2cb43de 100644
--- a/mkinstall.py
+++ b/mkinstall.py
@@ -17,7 +17,8 @@ Otherwise, I&#039;ll add a symlink.
 import os, shutil
</code></pre><pre><code>
 # Anything you want to skip:
-skip_us = [&quot;mkinstall.py&quot;, &quot;.svn&quot;, &quot;_vimrc&quot;]
+skip_us = [&quot;mkinstall.py&quot;, &quot;.svn&quot;, &quot;_vimrc&quot;, &quot;diffwrap.sh&quot;, &quot;lib&quot;,
+&nbsp;&nbsp;&nbsp;&nbsp;&quot;lynx_bookmarks.html&quot;, &quot;ipythonrc-matt&quot;, &quot;.git&quot;]
</code></pre><pre><code> 
 # Anything you want to copy rather than symlink to: 
 copy_us = [&quot;.vim&quot;]
Stage this hunk [y/n/a/d/j/J/?]? 
</code></pre></p>
<p>At this point, I will hit y.  Now that section of the file is staged to be committed.  That is not the same as committing it.<br />
Now git shows the next section of code that is different:<br />
<pre><code>
Stage this hunk [y/n/a/d/j/J/?]? y
@@ -60,7 +61,8 @@ for thing in copy_us:
&nbsp;&nbsp;&nbsp;&nbsp; if os.path.islink(homefile):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;A symbolic link to %s exists already, so I&#039;m not going to copy over it.&quot; % homefile
</code></pre><pre><code>&nbsp;&nbsp;
-&nbsp;&nbsp;&nbsp;&nbsp;elif os.path.exists(homefile): continue
+&nbsp;&nbsp;&nbsp;&nbsp;elif os.path.exists(homefile): 
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue
</code></pre><pre><code>&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; else:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; svnfile = os.path.join(svnpath, thing)
Stage this hunk [y/n/a/d/K/?]? 
</code></pre></p>
<p>I don&#8217;t want to stage this right now, so I hit n.  That&#8217;s the last edit in the file, so the interactive session completes.  Now when I run git diff &#8211;cached, which tells me what is about to be committed, look what I see:<br />
<pre><code>
$ git diff --cached mkinstall.py 
diff --git a/mkinstall.py b/mkinstall.py
index 4c6bb4e..a348ee1 100644
--- a/mkinstall.py
+++ b/mkinstall.py
@@ -17,7 +17,8 @@ Otherwise, I&#039;ll add a symlink.
 import os, shutil
</code></pre><pre><code> 
 # Anything you want to skip:
-skip_us = [&quot;mkinstall.py&quot;, &quot;.svn&quot;, &quot;_vimrc&quot;]
+skip_us = [&quot;mkinstall.py&quot;, &quot;.svn&quot;, &quot;_vimrc&quot;, &quot;diffwrap.sh&quot;, &quot;lib&quot;,
+&nbsp;&nbsp;&nbsp;&nbsp;&quot;lynx_bookmarks.html&quot;, &quot;ipythonrc-matt&quot;, &quot;.git&quot;]
</code></pre><pre><code>&nbsp;&nbsp;
 # Anything you want to copy rather than symlink to: 
 copy_us = [&quot;.vim&quot;]
</code></pre><br />
So now I&#8217;ll commit this edit with an appropriate remark:<br />
<pre><code>
$ git commit -m &quot;Added some more files to the list of files to be skipped&quot;
Created commit ce0478d: Added some more files to the list of files to be skipped
 1 files changed, 2 insertions(+), 1 deletions(-)
</code></pre></p>
<p>Now I&#8217;ll view the unstaged changes again in my file, and notice that the other change still remains:<br />
<pre><code>
$ git diff mkinstall.py 
diff --git a/mkinstall.py b/mkinstall.py
index a348ee1..2cb43de 100644
--- a/mkinstall.py
+++ b/mkinstall.py
@@ -61,7 +61,8 @@ for thing in copy_us:
&nbsp;&nbsp;&nbsp;&nbsp; if os.path.islink(homefile):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;A symbolic link to %s exists already, so I&#039;m not going to copy over it.&quot; % homefile
</code></pre><pre><code>&nbsp;&nbsp;
-&nbsp;&nbsp;&nbsp;&nbsp;elif os.path.exists(homefile): continue
+&nbsp;&nbsp;&nbsp;&nbsp;elif os.path.exists(homefile): 
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue
</code></pre><pre><code>&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; else:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; svnfile = os.path.join(svnpath, thing)
</code></pre></p>
<p>At this point, I can rerun git add -p and stage up more stuff to be committed.  In this case, it is more realistic that I would run</p>
<p><pre><code>git commit -a -m &quot;Made a silly style change&quot;
</code></pre><br />
That will stage and commit that last edit in one swoop.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tplus1.com/index.php/2008/10/31/break-up-changes-into-different-commits-with-git-add-p/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

