Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save luan0ap/dd39320d66ec76e3d4a38b1fda56a683 to your computer and use it in GitHub Desktop.

Select an option

Save luan0ap/dd39320d66ec76e3d4a38b1fda56a683 to your computer and use it in GitHub Desktop.

Revisions

  1. luan0ap revised this gist Jun 5, 2019. No changes.
  2. luan0ap revised this gist Jun 5, 2019. 1 changed file with 10 additions and 11 deletions.
    21 changes: 10 additions & 11 deletions how-to-squash-commits-in-git.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ## Squashing Git Commits

    ## O caminha fácil e flexível
    ## 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

    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.
    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 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.
    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.

    ### Combining the commits
    ### Combinando os commits

    To squash the last **3** commits into one:
    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

    #### If the commits **have** been pushed to the remote:
    #### 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*

    #### If the commits have **NOT** yet been pushed to the remote:
    #### Se os commits **NÃO** foram enviados para a branch remota:

    ```sh
    git push origin name-of-branch
    ```

    In other words, just a normal push like any other
    Em outras palavras, apenas um push normal como outro qualque

    ---

    Main source: http://stackoverflow.com/a/5201642/348995
    Source for info about when commits where already pushed: http://stackoverflow.com/a/5668050/348995
    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
  3. luan0ap revised this gist Jun 4, 2019. 1 changed file with 10 additions and 11 deletions.
    21 changes: 10 additions & 11 deletions how-to-squash-commits-in-git.md
    Original file line number Diff line number Diff line change
    @@ -1,39 +1,38 @@
    ## Squashing Git Commits

    ## The easy and flexible way
    ## O caminha fácil e flexível

    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).
    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).

    ***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.**
    ***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.**

    Switch to the master branch and make sure you are up to date:
    Troque para a branch master e certifique-se de estar tudo atualizado:

    ```sh
    git checkout master && git pull
    ```

    Merge your feature branch into the master branch locally:
    Faça merge sua feature branch na master localmente:

    ```sh
    git merge feature_branch
    ```

    Reset the local master branch to origin's state:
    Resete a sua branch local master para o estado de origem.

    ```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.
    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
    ```

    ([Source](http://makandracards.com/makandra/527-squash-several-git-commits-into-a-single-commit))
    ([Fonte](http://makandracards.com/makandra/527-squash-several-git-commits-into-a-single-commit))


    ## The hard(er) and less flexible way
    ## 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.

  4. luan0ap revised this gist Jun 3, 2019. No changes.
  5. @patik patik revised this gist Nov 3, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions how-to-squash-commits-in-git.md
    Original 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.
    ***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 fetch && git pull
    git checkout master && git pull
    ```

    Merge your feature branch into the master branch locally:
  6. @patik patik revised this gist Jan 26, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion how-to-squash-commits-in-git.md
    Original 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're plan to combine all commits into one, and you only changed one feature of the project.
    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

  7. @patik patik revised this gist Jan 25, 2016. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions how-to-squash-commits-in-git.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    ## Squashing commits the easy way
    ## 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))

    ## Squashing commits the hard way
    ## 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

  8. @patik patik revised this gist Jan 25, 2016. 1 changed file with 34 additions and 1 deletion.
    35 changes: 34 additions & 1 deletion how-to-squash-commits-in-git.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,37 @@
    ### Squashing the commits
    ## 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:

  9. @patik patik created this gist Jul 21, 2015.
    31 changes: 31 additions & 0 deletions how-to-squash-commits-in-git.md
    Original 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