Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
524 views
in Technique[技术] by (71.8m points)

rebase - Git squash all commits in branch without conflicting

A common development workflow for us is to checkout branch b, commit a bunch to it, then squash all those commits into one (still on b).

However, during the rebase -i process to squash all the commits, there are frequently conflicts at multiple steps.

I essentially want to alter the branch into one commit that represents the state of the repository at the time of the final commit on b

I've done some searching but I haven't found exactly what I'm looking for. I don't want to merge --squash because we would like to test the squashed feature branch before merging.

question from:https://stackoverflow.com/questions/17354353/git-squash-all-commits-in-branch-without-conflicting

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you don't need the commit information, then you could just do a soft reset. Then files remain as they were and when you commit, this commit will be on top of the commit you did reset to.

To find the commit to reset to:

git merge-base HEAD BRANCH_YOU_BRANCHED_FROM

Then

git reset --soft COMMIT_HASH

Then re-craft the commit, perhaps:

git commit -am 'This is the new re-created one commit'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...