-
-
Save luan0ap/dd39320d66ec76e3d4a38b1fda56a683 to your computer and use it in GitHub Desktop.
Revisions
-
luan0ap revised this gist
Jun 5, 2019 . No changes.There are no files selected for viewing
-
luan0ap revised this gist
Jun 5, 2019 . 1 changed file with 10 additions and 11 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,6 +1,6 @@ ## Squashing Git Commits ## O caminho fácil e flexível Este método evita conflitos durante eo merge, se você tem que periódicamente fazer pull da master em sua branch. Também da a oportuniadade de realizar squash em mais de um commit ou para re-organizar seu código completamente em diferentes commits (ex: se você terminou seu trabalho em três diferente features mas os commits não foram consecutivos). @@ -34,13 +34,13 @@ git commit ## O caminho difícil e menos flexível Este método somente permite você realizar squash dos últimos X consecutivos commits. Também, se você tiver realizado merge da master em sua branch ao longo do caminho, você terá que realizar merge manualmente o seu novo (squashed) commit na master e resolver os conflitos. use este método se você não realizou merge da maste em sua branch, e planeja combinar todos os commits em um, e você pode mudar apenas uma featuro do projeto; ou, independente das condições, você deve user esse método se planeja abrir um Pull Request para mesclar seu código. ### Combinando os commits Para realizar squas dos últimos **3** commits em um: ```sh git reset --soft HEAD~3 @@ -49,23 +49,22 @@ git commit -m "New message for the combined commit" ### Pushing the squashed commit #### Se os commits **foram** enviados para a branch remota: ```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* #### Se os commits **NÃO** foram enviados para a branch remota: ```sh git push origin name-of-branch ``` Em outras palavras, apenas um push normal como outro qualque --- Fonte principal: http://stackoverflow.com/a/5201642/348995 Fonte para informações sobre quando fazer commit onde já foi submetido: http://stackoverflow.com/a/5668050/348995 -
luan0ap revised this gist
Jun 4, 2019 . 1 changed file with 10 additions and 11 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,39 +1,38 @@ ## Squashing Git Commits ## O caminha fácil e flexível Este método evita conflitos durante eo merge, se você tem que periódicamente fazer pull da master em sua branch. Também da a oportuniadade de realizar squash em mais de um commit ou para re-organizar seu código completamente em diferentes commits (ex: se você terminou seu trabalho em três diferente features mas os commits não foram consecutivos). ***Nota: Você não pode usar esse método se você pretende abrir um Pull Request para realizer merge da sua branch. Esse método requer commits diretamente na master.** Troque para a branch master e certifique-se de estar tudo atualizado: ```sh git checkout master && git pull ``` Faça merge sua feature branch na master localmente: ```sh git merge feature_branch ``` Resete a sua branch local master para o estado de origem. ```sh git reset origin/master ``` Agora todas as suas mudanças são consideradas como "unstaged". Você pode coloca-las em "stage" e realizar o commit delas em um ou mais commits. ```sh git add . --all git commit ``` ([Fonte](http://makandracards.com/makandra/527-squash-several-git-commits-into-a-single-commit)) ## O caminho difícil e menos flexível 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. -
luan0ap revised this gist
Jun 3, 2019 . No changes.There are no files selected for viewing
-
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