git - How to squash the old commit and a recent merge commit -


when 2 commits made me 1 after another, can squash them

git rebase -i origin/{branch}~1 {branch} 

but sequence of commits different:

  1. my commit
  2. merge upstream: merge branch 'master' of github.com:...
  3. this pushed origin.

now git log , pull request show both original commit , merge commit. above rebase command shows other's commits came upstream, , no merge commit reason.

so how can squash commits if git rebase doesn't show them?

rebase removes merge commits entirely. reason simple enough: rebase copies commits, turning them changes , applying changes new base (hence name "re-base"). once copied, "abandon" original commits in favor of shiny new copies:

... <--b <--c   <-- master         \          d <--e <--f   <-- branch 

becomes:

... <--b <--c   <-- master              \               d' <--e' <--f'  <-- branch 

where d' shiny new copy of d, , on. in other words, rebase collects string of commits such d-e-f, turns them "what's different b d, what's different d e, , what's different e f. git can apply same changes c make d', re-apply d-vs-e changes d', , on.

it's unwise rebase any published (pushed) commit, unless pre-arrange else shares pushed-to repository understand , able coordinate this. essentially, they—the other people—are using commits you're abandoning in favor of shiny new ones; must also abandon commits in favor of shiny new ones, or else bring back old / dirty / broken / whatever commits.

merge commits have no clear way turned changes, have two previous (or parent) commits, rather one, , changes in merge result of combining changes each parent. (it's possible create new merge, pretty tricky, , it's not safe combine normal interactive rebase.)


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -