1

I made a lot of commits to test my repository. Now I want to fix my history without data loss. My history looks like this:

A -> B -> C -> TEST D -> TEST E

But it should be this:

A -> B -> C (C + TEST D + TEST E)

How can I do it? Can rebase or stash help me?

UPD Ok this is my commit history:

commit 9f2c2e66d344aa27a5e681eb64c84738f2cd1d49
Author: babobka <babobka@bk.ru>
Date:   Sat Jan 14 23:35:36 2017 +0300

    Fixed files

commit 9ab55a4e4352daa9e5c27e9243d79a8c14dd6551
Merge: b52872c 856ee3f
Author: bbk <dolgopolov.work@gmail.com>
Date:   Sat Jan 14 23:29:16 2017 +0300

    Merged in develop (pull request #1)

    New tests. New project structure. FindBugs plugin.

commit 856ee3fb4725564c1c5c976eacadb6e21aa2b937
Author: babobka <babobka@bk.ru>
Date:   Sat Jan 14 23:24:02 2017 +0300

    New tests. New project structure. FindBugs plugin.

commit b52872c300bde67154cec3b732755a47f9ff76cd
Author: babobka <babobka@bk.ru>
Date:   Mon Jan 9 23:36:02 2017 +0300

    Very big refactor.Can not remember what was done.

commit 0b330267150db40fb814bfc21387762d80a99e44
Author: babobka <babobka@bk.ru>
Date:   Tue Jan 3 01:13:05 2017 +0300

    First commit

I made git rebase -i 9ab55a4e4352daa9e5c27e9243d79a8c14dd6551 -m 'Rebasing', but I can not see any changes. Still the same history.

Tony
  • 459
  • 1
  • 5
  • 18
  • 3
    Possible duplicate of [Squash my last X commits together using Git](http://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git) – acm Jan 14 '17 at 21:07
  • what I understand is you want to "squash" the last few commits into one? See if this helps http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html – sinanspd Jan 14 '17 at 21:10
  • Are you edit rebase interactive mode config? Are you change some of pick words to squash? – oklas Jan 14 '17 at 21:20
  • @oklas, WHAT??? – Tony Jan 14 '17 at 21:23
  • Did you go to above link from @acm? Did you read `replace "pick" on the second and subsequent commits with "squash" or "fixup", as described in` [the manual](http://git-scm.com/docs/git-rebase#_interactive_mode) – oklas Jan 14 '17 at 21:33

1 Answers1

1

You can use interactive mode of rebase command

git rebase -i HEAD~2

Where HEAD~2 - 2 is nuber of commits which you need to envolve into operation. Interactive mode show short help for you. Mark squash (by replace pick word) that commits which you need to join togather.

Tip: first time to do it better create branch and do it in separated brach. In separated branch you can check results to more understand how rebase is worked. And simple to rollback by checkout original branch if some trouble or unexpected behaviour you meet.

oklas
  • 7,935
  • 2
  • 26
  • 42