Git split a branch into one new post

So, let's say I have a main branch, we will call the "master". I created a branch called the "new feature". I made a ton of commits in this thread so that I can go back in time, but when developing this function, I did quite a lot back and forth, so the commit log is pretty dirty.

If I looked at git diff master..new-feature for example.

If I wanted to create only one new fresh commit on "master" that includes all changes between the two branches, what is the most efficient way to do this?

+7
source share
5 answers
git checkout master git merge --squash new-feature git commit 

A commit message will be posted showing the entire list of commits being merged / crushed, but you can, of course, edit this as you want.

+17
source

Another option that might work better for you would be to create a patch file using git diff --patch > "patch filename" and then fix them in your main branch using git apply "patch file name" .

User page for git-diff (especially "Creating patches with -p"): http://www.kernel.org/pub/software/scm/git/docs/git-diff.html

User page for git-apply: http://www.kernel.org/pub/software/scm/git/docs/git-apply.html

+2
source

You can use interactive redirects for this: git rebase --interactive . Then just use the squash option. It uses updates only from commit, but does not create commit.

+1
source

Use git rebase --interactive HEAD ~ (however many commits want squash). for example, git rebase --interactive HEAD ~ 5. This will load your last 5 commits and bring up a message editor window. Each message will have a β€œselect” at the beginning. Go to the last post, change 'pick' to 'squash' and exit. A new window will open asking for a commit message. This will be a new post about committing squash commits. Exit and it will flip all the commits into one new.

Here is an example: https://ariejan.net/2011/07/05/git-squash-your-latests-commits-into-one

+1
source

You can transfer everything to your function branch, and then merge it into a wizard that accepts its own for all changes.

Here's a stack overflow question with a great answer on how to do this: Is there a "their" version of "git merge -s ours"

0
source

All Articles