0

I'm learning git and I'm trying to make this:

* commit 5 (master) (dev)
|
* commit 4
|\
| * commit 3
|/
* commit 2
|
* commit 1

Become this:

* commit 5 (master) (dev)
|
* commit 4
|
* commit 3
|
* commit 2
|
* commit 1

Here is actual git log output:

enter image description here

I've tried rebase and cherry picking, but didn't worked.

How do I do this?

matt
  • 515,959
  • 87
  • 875
  • 1,141
ztKn
  • 1
  • 1
  • 1
  • 2
    You can’t move a commit. You can put a commit that LOOKS like commit 3 after commit 2, but it will not BE commit 3. – matt Feb 04 '20 at 18:49
  • Why do you want to do this? – Michele Dorigatti Feb 04 '20 at 18:51
  • Can you explain what you mean? Your drawings aren't clear. – Michele Dorigatti Feb 04 '20 at 18:52
  • @matt how do I do this? – ztKn Feb 04 '20 at 18:54
  • 1
    Impossible to answer without better graphs or (better) a description of what you did. You started on master. You made commits 1 and 2. You started branch dev, checked it out, and made commit 3. Then what? – matt Feb 04 '20 at 18:58
  • @matt I started master, then created commits 1 and 2, then created the dev branch and chekout to it, then created commit 3 and merged it into master. Commit 4 is the merge, and commit 5 is a rebase of dev into master. – ztKn Feb 04 '20 at 19:05
  • @MicheleDorigatti Sorry if I didn't make the problem clear enough. I'm only trying to learn how to make the timeline becomes a straight line to be more simple and to know how to do something like that if it becomes necessary eventually. – ztKn Feb 04 '20 at 19:14
  • 1
    Ok so you _didn't_ fast-forward. Your commit 4 is a merge commit. – matt Feb 04 '20 at 20:20
  • 1
    Why do you think making the history completely linear would be an improvement over what you have now? – chepner Feb 04 '20 at 20:23
  • Likely duplicate of https://stackoverflow.com/questions/17577409/git-remove-merge-commit-from-history though it is a little hard to tell from the way the question was asked. Commit 4 is a merge commit so what you really want is for master to go `1 -> 2 -> 3 -> 5`. – matt Feb 04 '20 at 20:34
  • @chepner I'm just trying to avoid that this graph becomes a complete mess later. – ztKn Feb 04 '20 at 20:36
  • 1
    Then just take care to do fast-forward commits in the future (using the `--ff-only` option). Excising small merges isn't worth the effort, IMO. – chepner Feb 04 '20 at 20:38
  • Merge commits do not constitute a "mess". – matt Feb 04 '20 at 21:21

0 Answers0