git checkout $feature & git reset -hard tmp.Checkout feature and git reset -hard tmp ( feature's original contents are gone, and it is now basically tmp, but renamed).tmp is now master + 1 commit (containing all changes). (This is the only step you cannot have a script do for you).Manually solve all remaining "real conflicts".Merge all feature changes into tmp (without any commits, only staged file changes).git checkout master & git pull & git checkout -b tmp.Create a local tmp branch of off master.This is my slightly shorter transcription of his advice: I found Felix Rieseberg's solution to be the best. How to squash messy branches? Use a temporary branch! This I found to be one of the most annoying issues to deal with. I often end up having master commits on my feature branch (call it feature) that cause conflicts against themselves. In previous answers, I have not seen any information on how to deal with " messy branches" and " self conflicts". automatically uses the branch you are currently on.Īnd if you use that, you can also use an alias, as the command doesn't rely on the branch name. force"įor the reset, you can do git reset $(git merge-base master $(git rev-parse -abbrev-ref HEAD)) no need for git add -A, since git reset -soft only moves HEAD, and leaves the index untouched (in other words, the files are already "added").ĮDIT: you will need to use git push -force (or git push -force-with-lease).no need for git branch -show-current since HEAD is already a reference to that branch.Git reset -soft $(git merge-base master HEAD) Or, as noted by Hiroki Osame in the comments: git switch yourBranch Note: git branch -show-current has been introduced with Git 2.22 (Q2 2019). Note: finding that origin branch isn't easy/possible with Git (the visual way is often the easiest, as seen here). This isn't perfect as it implies you know from which branch " yourBranch" is coming from. Git reset $(git merge-base master $(git branch -show-current)) If you need the following commands to work for any default branch, replace master with $.Īnd define defaultBranch=$(git config -get faultBranch || echo main).īack to the solution: (to squash all your commit) reset the index to master: git checkout yourBranch In order to provide the most universally applicable examples, as well as avoid confusion, this answer shall assume Git's default configuration. Git version 2.28 (Q3 2020) introduced configurable default branch names, which means your remote repository may optionally use another default branch name such as main. Note: Git's default branch name is still master with Git version 2.41 (Q3 2023), as seen in git init man page. Another way to squash all your commits is to reset the index to master:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |