threads / discuss / 17140

how to combine 2 commits?

Subject: how to combine 2 commits?

## tl;dr

9 messages between Jan 13, 2009 and Jan 13, 2009.

replies: 8people: 7as markdown or json

bill lam· Jan 13, 2009, 04:54 UTC · lore

Sorry I don't know the correct git terminology for it. I make some changes to scripts but also accidentally changed all scripts to use dos linefeed. Failed to notice this and commit all changes. Then I tried to correct it by changing all scripts back to unix linefeed and commit again.

How to combine these 2 commits so that the changes of linefeed cancel out each other and the history only shows the intended changes of the few scripts.

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩234 李白  怨情
    美人捲珠簾  深坐蹙蛾眉  但見淚痕濕  不知心恨誰
Jeff Whiteside· Jan 13, 2009, 05:08 UTC · re: bill lam · lore

Re: how to combine 2 commits?

git terminology is "squash"
On Mon, Jan 12, 2009 at 11:54 PM, bill lam <cbill.lam@gmail.com> wrote:
Show 21 quoted lines
>
> Sorry I don't know the correct git terminology for it.  I make some
> changes to scripts but also accidentally changed all scripts to use
> dos linefeed.  Failed to notice this and commit all changes. Then I
> tried to correct it by changing all scripts back to unix linefeed and commit again.
>
> How to combine these 2 commits so that the changes of linefeed cancel
> out each other and the history only shows the intended changes of the
> few scripts.
>
> --
> regards,
> ====================================================
> GPG key 1024D/4434BAB3 2008-08-24
> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
> 唐��234 李白  怨情
>    美人�灾楹�  深坐蹙蛾眉  但���I痕��  不知心恨�l
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Boyd Stephen Smith Jr.· Jan 13, 2009, 05:27 UTC · re: bill lam · lore

Re: how to combine 2 commits?

On Monday 12 January 2009, bill lam <cbill.lam@gmail.com> wrote about 'how to combine 2 commits?':

>How to combine these 2 commits so that the changes of linefeed cancel
>out each other and the history only shows the intended changes of the
>few scripts.

Two ways I can think of: git rebase --interactive (read "git help rebase" first) git merge --squash (read "git help merge" first)

The rebase is probably semantically closer to how you are thinking about things right now.

-- 
Boyd Stephen Smith Jr.                     ,= ,-_-. =. 
bss@iguanasuicide.net                     ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' 
http://iguanasuicide.net/                      \_/     
Imran M Yousuf· Jan 13, 2009, 05:32 UTC · re: Boyd Stephen Smith Jr. · lore

Re: how to combine 2 commits?

On Tue, Jan 13, 2009 at 11:27 AM, Boyd Stephen Smith Jr. <bss@iguanasuicide.net> wrote:

Show 12 quoted lines
> On Monday 12 January 2009, bill lam <cbill.lam@gmail.com> wrote about 'how
> to combine 2 commits?':
>>How to combine these 2 commits so that the changes of linefeed cancel
>>out each other and the history only shows the intended changes of the
>>few scripts.
>
> Two ways I can think of:
> git rebase --interactive (read "git help rebase" first)
> git merge --squash (read "git help merge" first)
>
> The rebase is probably semantically closer to how you are thinking about
> things right now.

Another way I can think of is - git format-patch + git apply, i.e. first generate 2 patches for the 2 commits and then apply them one on top of another.

Best regards,
Imran
Show 6 quoted lines
> --
> Boyd Stephen Smith Jr.                     ,= ,-_-. =.
> bss@iguanasuicide.net                     ((_/)o o(\_))
> ICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-'
> http://iguanasuicide.net/                      \_/
>
-- 
Imran M Yousuf
Entrepreneur & Software Engineer
Smart IT Engineering
Dhaka, Bangladesh
Email: imran@smartitengineering.com
Blog: http://imyousuf-tech.blogs.smartitengineering.com/
Mobile: +880-1711402557
bill lam· Jan 13, 2009, 07:51 UTC · re: Boyd Stephen Smith Jr. · lore

Re: how to combine 2 commits?

On Mon, 12 Jan 2009, Boyd Stephen Smith Jr. wrote:
> git rebase --interactive (read "git help rebase" first)
I tried rebase the last 3 commit, but it failed.

bill@b2j:jproject$ git log --pretty=oneline | head 39ed365c11391bede0e1b6578adfac6619b78c0a for yajpp to use unix LF 70c812db2439bc84a8dd7ea831067b9ebf29885c revert last crlf error f338a768d635b868e6fddaae670ad91d46ea7c4e format scripts

bill@b2j:jproject$ git rebase -i HEAD~3 error: Entry 'trunk/jcalc/mmenu-mm.ijs' not uptodate. Cannot merge. fatal: merging of trees a1eafe6cdbb428f851d6ca878bbc53149fb7e7eb and a00e6dcd3ec3f4ffde0d1aad1958db724093de69 failed

Could not apply 70c812d... revert last crlf error

It looks like cannot resolve conflict of linefeed changes. It was expected all scripts will conflict, so I have to abort the rebase.

What is the procedure to generate a patch of the HEAD from HEAD~4, then cancel all changes from HEAD~3 up to HEAD, and then apply the patch to the previous HEAD~4 ?

BTW, what is the norm of reply in this list, should it be reply to list only, or reply to group (list plus all cc)?

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩213 李商隱  無題二首之二
    颯颯東風細雨來  芙蓉塘外有輕雷  金蟾齧璅燒香入  玉虎牽絲汲井迴
    賈氏窺簾韓掾少  宓妃留枕魏王才  春心莫共花爭發  一寸想思一寸灰
Stephen R. van den Berg· Jan 13, 2009, 11:20 UTC · re: bill lam · lore

Re: how to combine 2 commits?

bill lam wrote:
>BTW, what is the norm of reply in this list, should it be reply to
>list only, or reply to group (list plus all cc)?
This list prefers list plus all cc.
-- 
Sincerely,
           Stephen R. van den Berg.

"I have a *cunning* plan!"
Sitaram Chamarty· Jan 13, 2009, 06:35 UTC · re: bill lam · lore

Re: how to combine 2 commits?

On 2009-01-13, bill lam <cbill.lam@gmail.com> wrote:
Show 9 quoted lines
> Sorry I don't know the correct git terminology for it.  I make some
> changes to scripts but also accidentally changed all scripts to use
> dos linefeed.  Failed to notice this and commit all changes. Then I
> tried to correct it by changing all scripts back to unix
> linefeed and commit again.
>
> How to combine these 2 commits so that the changes of linefeed cancel
> out each other and the history only shows the intended changes of the
> few scripts.

I tend to make lots of small commits on the work tree, and having to combine them meaningfully later.

I like using "git rebase -i HEAD~5" (if I want to rebase the last 5 commits). In the editor that pops up, I reorder the ones that I know should be together, and on each set to be squashed, I change the "pick" to "s" (for squash) on all but the first one. Save the file and it's all done.

Works like a charm. For me, moving commits around in an editor, deleting them even, is very intuitive.

Matthieu Moy· Jan 13, 2009, 06:48 UTC · re: Sitaram Chamarty · lore

Re: how to combine 2 commits?

Sitaram Chamarty <sitaramc@gmail.com> writes:
Show 5 quoted lines
> I like using "git rebase -i HEAD~5" (if I want to rebase the
> last 5 commits).  In the editor that pops up, I reorder the
> ones that I know should be together, and on each set to be
> squashed, I change the "pick" to "s" (for squash) on all but
> the first one.  Save the file and it's all done.
And right after, you probably want to do stg like
  git diff master@{1} master

to see whether you actually changed the result by reordering your patches.

-- 
Matthieu
Sitaram Chamarty· Jan 13, 2009, 11:32 UTC · re: Matthieu Moy · lore

Re: how to combine 2 commits?

On 2009-01-13, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
Show 14 quoted lines
> Sitaram Chamarty <sitaramc@gmail.com> writes:
>
>> I like using "git rebase -i HEAD~5" (if I want to rebase the
>> last 5 commits).  In the editor that pops up, I reorder the
>> ones that I know should be together, and on each set to be
>> squashed, I change the "pick" to "s" (for squash) on all but
>> the first one.  Save the file and it's all done.
>
> And right after, you probably want to do stg like
>
>   git diff master@{1} master
>
> to see whether you actually changed the result by reordering your
> patches.

I used to do that, but now I've stopped. If it doesn't conflict, I know it's good. I go straight to the equivalent of make && make test.

I must mention though, that I don't reorder the relative sequences of commits affecting the same file/set of files. That might have something to do with my confidence :-)

← back to recent threads