Removing merge commits in Git -


here, have our commit log repo. can see "merge branch...into..." commits, , after commit, branch merged.

i need delete merge commit, not discard changes. default rebasing doesn't show merge commits.

enter image description here

if want apply changes of commits without including merge commit (which roland smith pointed out considered bad practice) can use git rebase following workflow:

  1. checkout branch want changes on (let's master): git checkout master
  2. reset master commit before merge want undo: git reset --hard <hash of prior commit>. make sure there no uncommitted changes on branch working on or command wipe them out.
  3. checkout branch containing updates want "merge" master without merging (let's call dev): git checkout dev.
  4. rebase dev onto master. put head commit of dev upstream recent commit master points to: git rebase master (see the docs more information).
  5. fix merge conflicts result during rebase (they have happened in normal merge too).
  6. the rebased branch should have of commits following latest commit on master. port on master, check out master (git checkout master) , merge new branch git merge dev. pull changes onto master without adding merge commit.
  7. once you're sure updated master branch looks okay, you'll have update branch on remote repositories too. because you're undoing prior history, when push branch you'll have use --force (or -f) flag remote repo accept changes i.e.: git push origin master --force.

that's there it. after this, commits on dev branched off of master should upstream pre-merge commit above.

note: running rebase permanently update commit history changed branches. safety, recommend taking 1 of 2 methods:

  1. per @dacav's suggestion, keep track of commit hashes each branch before update anything. if things go pear shaped, run git reset --hard <original_commit_hash> put branch on original commit.
  2. make backup copies of both branches before rebase pointing @ original commit:

    git checkout -b master_bk git checkout -b dev_bk


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -