Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jacob Keller <jacob.e.keller@intel.com>
Cc: git@vger.kernel.org, Jacob Keller <jacob.keller@gmail.com>
Subject: Re: [PATCH v2] reset: add an example of how to split a commit into two
Date: Fri, 03 Feb 2017 12:46:20 -0800	[thread overview]
Message-ID: <xmqqzii3dmub.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170203202833.17666-1-jacob.e.keller@intel.com> (Jacob Keller's message of "Fri, 3 Feb 2017 12:28:33 -0800")

Jacob Keller <jacob.e.keller@intel.com> writes:

> +Split a commit into two::

Let's say "...into two (or more)" to match what appears in
"SPLITTING COMMITS" section of "rebase -i" documentation.  Yours is
written as a sequence of more concrete steps than the existing one
over there, so it may also make sense to add reference to bring
readers of "git rebase --help" to this section.

> ++
> +Suppose that you have created a commit, but later decide that you want to break
> +apart the changes into two logical chunks and commit each separately. You want

"two (or more)" again.  In <5> you already hint that the user can
repeat 2-4 number of times.

> +to include part of the original commit into the first commit, while including
> +the remainder in a second commit. You can use git reset to rewind the history
> +without changing the index, and then use git add -p to interactively select
> +which hunks to put into the first commit.
> ++
> +------------
> +$ git reset HEAD^                           <1>
> +$ git add -p                                <2>
> +$ git diff --cached                         <3>
> +$ git commit -c HEAD@{1}                    <4>
> +...
> +$ git add ...                               <5>
> +$ git diff --cached                         <6>
> +$ git commit ...                            <7>
> +------------
> ++
> +<1> First, reset the history back one commit so that we remove the original
> +    commit, but leave the working tree with all the changes.
> +<2> Now, interactively select hunks to add to a new commit using git add -p.
> +    This will ask for each hunk separately and you can use simple commands like
> +    "yes, include", "no don't include" or even "edit".
> +<3> Once satisfied with the hunks, you should verify that it is what you
> +    expected by using git diff --cached to show all changes in the index.
> +<4> Next, commit the changes stored in the index. "-c" specifies to load the
> +    editor with a commit message from a previous commit so that you can re-use the
> +    original commit message. HEAD@{1} is special notation to reference what
> +    HEAD used to be prior to the reset command. See linkgit:git-reflog[1] for
> +    more details.
> +<5> Now you've created the first commit, and can repeat steps 2-4 as often as
> +    you like to break the work into any number of commits. Here we show a second
> +    step which simply adds the remaining changes.
> +<6> Then check again that the changes are what you expected to add.
> +<7> And finally commit the remaining changes.
> +

  reply	other threads:[~2017-02-03 20:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-03 20:28 [PATCH v2] reset: add an example of how to split a commit into two Jacob Keller
2017-02-03 20:46 ` Junio C Hamano [this message]
2017-02-04 11:06 ` Duy Nguyen
2017-02-04 12:16   ` Philip Oakley
2017-02-04 12:36     ` Duy Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqzii3dmub.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jacob.e.keller@intel.com \
    --cc=jacob.keller@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox