1

Hi am trying to move my changes from the dev branch back to the mainline; without having all incremental commits show up in the history/log .I was trying to do it with cherry-pick but guess I am doing something wrong.

Below is how my branches look like:

Branch Mainline :

commit A [introduced after I branched to dev from mainline]
commit B
commit C
.... so on

Branch  Dev:

Commit P  [not pushed to remote]
Commit Q  [not pushed to remote]
more than 10 different commits in between [pushed to remote dev branch]
Commit B [Based on mainline]

Required result in Branch Mainline:

Commit allDev [A single commit with everything from the dev branch after Commit B ]
Commit A [This might need a merge commit since overlapping code from dev]
Commit B
Commit C
... so on

Would be grateful if I could get some help here.

Rini
  • 65
  • 1
  • 8

1 Answers1

0

Use a squash merge. This will leave the incremental commits in the branch and create one new big commit in master. Assuming you are on a feature branch:

$ git checkout master
$ git merge --squash feature
$ git commit

As per git-merge docs:

--squash

--no-squash

Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the HEAD, or record $GIT_DIR/MERGE_HEAD (to cause the next git commit command to create a merge commit). This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).

With --no-squash perform the merge and commit the result. This option can be used to override --squash.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111