1

My current git commit history looks like -

git log -4 --graph

*   commit B
|\  Merge: D C
| | 
| | 
| * commit C
| |
* | commit D
|/  
|
|
* commit E 

The merge commit B contains some additional changes apart from the (D + C) merge change.

I want to squash the latest merge commit B with the past 2 commits C and D.

I want my commit history to look like -

* commit A (B+C+D)
|
|
|
* commit E
Aman Vidura
  • 85
  • 2
  • 10
  • 1
    Use `git reset --soft`: see the accepted answer to http://stackoverflow.com/q/5203535/1256452 (you don't want to set up `.git/MERGE_HEAD`, just do the soft reset to commit `D`, and then make new commit `A` with `git commit`). – torek Nov 02 '16 at 14:09
  • @torek I did a soft reset and committed the changes. My local commit history changed as expected. But I was not able to push it to my remote repository. I get the message - 'Everything up-to-date'. – Aman Vidura Nov 03 '16 at 04:12
  • What precisely was your `git push` command, and if you used `git push` with no additional arguments, what is your `push.default` setting and what is the upstream set to for the current branch? (If your `push.default` is unset, what does `git --version` produce?) – torek Nov 03 '16 at 04:52
  • Using git reset --soft caused a detached head issue when the push was made to to the branch. git reset --soft origin/develop followed by commit and push did the trick. I was able to overcome the detached head issue. – Aman Vidura Nov 03 '16 at 07:57
  • `git reset --soft` does not detach HEAD. If it is *already* detached, though, it will reset HEAD as usual, without moving any branch *name*, meaning you continue to have a detached HEAD. That would explain the behavior you saw. – torek Nov 03 '16 at 08:28

0 Answers0