Last active
July 24, 2025 08:48
-
Star
(384)
You must be signed in to star a gist -
Fork
(81)
You must be signed in to fork a gist
Revisions
-
patik revised this gist
Nov 3, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,12 +4,12 @@ This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive). ***Note: You cannot use this method if you intend to open a pull request to merge your feature branch.* This method requires committing directly to master.** Switch to the master branch and make sure you are up to date: ```sh git checkout master && git pull ``` Merge your feature branch into the master branch locally: -
patik revised this gist
Jan 26, 2016 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,8 @@ This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive). *Note: You cannot use this method if you intend to open a pull request to merge your feature branch.* This method requires committing directly to master. Switch to the master branch and make sure you are up to date: ```sh @@ -35,7 +37,7 @@ git commit This method only allows you to squash the last X consecutive commits into a single commit. Also, if you have merged master into your branch along the way, you will have to manually merge your new (squashed) commit into master and resolve the merge conflicts. Use this method if you have not merged master into your branch, you plan to combine all commits into one, and you only changed one feature of the project; or, regardless of those conditions, you must use this method if you intend to open a pull request to merge your code. ### Combining the commits -
patik revised this gist
Jan 25, 2016 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ ## Squashing Git Commits ## The easy and flexible way This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive). @@ -29,7 +31,11 @@ git commit ([Source](http://makandracards.com/makandra/527-squash-several-git-commits-into-a-single-commit)) ## The hard(er) and less flexible way This method only allows you to squash the last X consecutive commits into a single commit. Also, if you have merged master into your branch along the way, you will have to manually merge your new (squashed) commit into master and resolve the merge conflicts. Use this method if you have not merged master into your branch, you're plan to combine all commits into one, and you only changed one feature of the project. ### Combining the commits -
patik revised this gist
Jan 25, 2016 . 1 changed file with 34 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,37 @@ ## Squashing commits the easy way This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive). Switch to the master branch and make sure you are up to date: ```sh git checkout master && git fetch && git pull ``` Merge your feature branch into the master branch locally: ```sh git merge feature_branch ``` Reset the local master branch to origin's state: ```sh git reset origin/master ``` Now all of your changes are considered as unstaged changed. You can stage and commit them into one or more commits. ```sh git add . --all git commit ``` ([Source](http://makandracards.com/makandra/527-squash-several-git-commits-into-a-single-commit)) ## Squashing commits the hard way ### Combining the commits To squash the last **3** commits into one: -
patik created this gist
Jul 21, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ ### Squashing the commits To squash the last **3** commits into one: ```sh git reset --soft HEAD~3 git commit -m "New message for the combined commit" ``` ### Pushing the squashed commit #### If the commits **have** been pushed to the remote: ```sh git push origin +name-of-branch ``` *The plus sign forces the remote branch to accept your rewritten history, otherwise you will end up with divergent branches* #### If the commits have **NOT** yet been pushed to the remote: ```sh git push origin name-of-branch ``` In other words, just a normal push like any other --- Main source: http://stackoverflow.com/a/5201642/348995 Source for info about when commits where already pushed: http://stackoverflow.com/a/5668050/348995