Git: How to squash all commits on `master` branch? [duplicate]How to squash all git commits into one?git push --force-with-lease vs. --forceHow to clone all remote branches in Git?How to modify existing, unpushed commit messages?How to undo 'git add' before commit?How do I undo the most recent local commits in Git?Move the most recent commit(s) to a new branch with GitHow do I check out a remote Git branch?How do I delete a Git branch locally and remotely?How to revert a Git repository to a previous commitHow can I reconcile detached HEAD with master/origin?How do I rename a local Git branch?

If you had a giant cutting disc 60 miles diameter and rotated it 1000 rps, would the edge be traveling faster than light?

Are DSA and ECDSA provably secure assuming DL security?

How to project 3d image in the planes xy, xz, yz?

Taxi Services at Didcot

What can plausibly explain many of my very long and low-tech bridges?

Does Disney no longer produce hand-drawn cartoon films?

Is open-sourcing the code of a webapp not recommended?

Investing in a Roth IRA with a Personal Loan?

Is the term 'open source' a trademark?

Where does "0 packages can be updated." come from?

Soft question: Examples where lack of mathematical rigour cause security breaches?

What is wrong with this proof that symmetric matrices commute?

Is it a problem if <h4>, <h5> and <h6> are smaller than regular text?

How to tell your grandparent to not come to fetch you with their car?

How to officially communicate to a non-responsive colleague?

Why is one of Madera Municipal's runways labelled with only "R" on both sides?

How to retract an idea already pitched to an employer?

What's the name of this light airplane?

Should I give professor gift at the beginning of my PhD?

Was there a priest on the Titanic who stayed on the ship giving confession to as many as he could?

Show that this function is bounded

Winning Strategy for the Magician and his Apprentice

Using "subway" as name for London Underground?

What's the largest optical telescope mirror ever put in space?



Git: How to squash all commits on `master` branch? [duplicate]


How to squash all git commits into one?git push --force-with-lease vs. --forceHow to clone all remote branches in Git?How to modify existing, unpushed commit messages?How to undo 'git add' before commit?How do I undo the most recent local commits in Git?Move the most recent commit(s) to a new branch with GitHow do I check out a remote Git branch?How do I delete a Git branch locally and remotely?How to revert a Git repository to a previous commitHow can I reconcile detached HEAD with master/origin?How do I rename a local Git branch?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1
















This question already has an answer here:



  • How to squash all git commits into one?

    14 answers



I'm looking for a way to squash all git commits into a single big commit in master branch. I fully understand the consequences of what I'm trying to do, no need to explain that this is dangerous or that it's not the right way to go - I want to lose all my history and turn this repository into a single big commit.



The main problem is: I have no other living branches, no local commits, and all of the previous commits have already been pushed to remote master.



Hacky scripts are also welcome.










share|improve this question















marked as duplicate by phd, JB Nizet, Community Mar 25 at 14:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • First thing that comes to my mind: git rebase -i <first-commit-hash>. Then use your editor's query replace functionality to replace all the pick by squashand save. Then git push --force.

    – JB Nizet
    Mar 24 at 16:33











  • stackoverflow.com/search?q=%5Bgit%5D+squash+all+commits

    – phd
    Mar 24 at 17:03











  • Hm there are many solutions so this, not sure which one is right

    – milosmns
    Mar 25 at 10:48












  • @phd I'll check out that other one, it didn't come up in my searches though.

    – milosmns
    Mar 25 at 10:48

















1
















This question already has an answer here:



  • How to squash all git commits into one?

    14 answers



I'm looking for a way to squash all git commits into a single big commit in master branch. I fully understand the consequences of what I'm trying to do, no need to explain that this is dangerous or that it's not the right way to go - I want to lose all my history and turn this repository into a single big commit.



The main problem is: I have no other living branches, no local commits, and all of the previous commits have already been pushed to remote master.



Hacky scripts are also welcome.










share|improve this question















marked as duplicate by phd, JB Nizet, Community Mar 25 at 14:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • First thing that comes to my mind: git rebase -i <first-commit-hash>. Then use your editor's query replace functionality to replace all the pick by squashand save. Then git push --force.

    – JB Nizet
    Mar 24 at 16:33











  • stackoverflow.com/search?q=%5Bgit%5D+squash+all+commits

    – phd
    Mar 24 at 17:03











  • Hm there are many solutions so this, not sure which one is right

    – milosmns
    Mar 25 at 10:48












  • @phd I'll check out that other one, it didn't come up in my searches though.

    – milosmns
    Mar 25 at 10:48













1












1








1









This question already has an answer here:



  • How to squash all git commits into one?

    14 answers



I'm looking for a way to squash all git commits into a single big commit in master branch. I fully understand the consequences of what I'm trying to do, no need to explain that this is dangerous or that it's not the right way to go - I want to lose all my history and turn this repository into a single big commit.



The main problem is: I have no other living branches, no local commits, and all of the previous commits have already been pushed to remote master.



Hacky scripts are also welcome.










share|improve this question

















This question already has an answer here:



  • How to squash all git commits into one?

    14 answers



I'm looking for a way to squash all git commits into a single big commit in master branch. I fully understand the consequences of what I'm trying to do, no need to explain that this is dangerous or that it's not the right way to go - I want to lose all my history and turn this repository into a single big commit.



The main problem is: I have no other living branches, no local commits, and all of the previous commits have already been pushed to remote master.



Hacky scripts are also welcome.





This question already has an answer here:



  • How to squash all git commits into one?

    14 answers







git






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 17:03









phd

26.8k52852




26.8k52852










asked Mar 24 at 16:24









milosmnsmilosmns

1,80532232




1,80532232




marked as duplicate by phd, JB Nizet, Community Mar 25 at 14:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by phd, JB Nizet, Community Mar 25 at 14:42


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • First thing that comes to my mind: git rebase -i <first-commit-hash>. Then use your editor's query replace functionality to replace all the pick by squashand save. Then git push --force.

    – JB Nizet
    Mar 24 at 16:33











  • stackoverflow.com/search?q=%5Bgit%5D+squash+all+commits

    – phd
    Mar 24 at 17:03











  • Hm there are many solutions so this, not sure which one is right

    – milosmns
    Mar 25 at 10:48












  • @phd I'll check out that other one, it didn't come up in my searches though.

    – milosmns
    Mar 25 at 10:48

















  • First thing that comes to my mind: git rebase -i <first-commit-hash>. Then use your editor's query replace functionality to replace all the pick by squashand save. Then git push --force.

    – JB Nizet
    Mar 24 at 16:33











  • stackoverflow.com/search?q=%5Bgit%5D+squash+all+commits

    – phd
    Mar 24 at 17:03











  • Hm there are many solutions so this, not sure which one is right

    – milosmns
    Mar 25 at 10:48












  • @phd I'll check out that other one, it didn't come up in my searches though.

    – milosmns
    Mar 25 at 10:48
















First thing that comes to my mind: git rebase -i <first-commit-hash>. Then use your editor's query replace functionality to replace all the pick by squashand save. Then git push --force.

– JB Nizet
Mar 24 at 16:33





First thing that comes to my mind: git rebase -i <first-commit-hash>. Then use your editor's query replace functionality to replace all the pick by squashand save. Then git push --force.

– JB Nizet
Mar 24 at 16:33













stackoverflow.com/search?q=%5Bgit%5D+squash+all+commits

– phd
Mar 24 at 17:03





stackoverflow.com/search?q=%5Bgit%5D+squash+all+commits

– phd
Mar 24 at 17:03













Hm there are many solutions so this, not sure which one is right

– milosmns
Mar 25 at 10:48






Hm there are many solutions so this, not sure which one is right

– milosmns
Mar 25 at 10:48














@phd I'll check out that other one, it didn't come up in my searches though.

– milosmns
Mar 25 at 10:48





@phd I'll check out that other one, it didn't come up in my searches though.

– milosmns
Mar 25 at 10:48












2 Answers
2






active

oldest

votes


















2














I would use git reset --soft



git reset --soft id-of-first-revision-of-master
git commit --amend -m "single commit for master"


Then you can push --force wherever you need that new branch.






share|improve this answer
































    1














    You can still modify the history on the upstream by using git push --force-with-lease. However you have to be aware of the consequences.



    Using git push --force will create a parallel tree on your upstream so all the developers may find themselves lost in a legacy branch.



    In order to squash your history, simply do:



    git rebase -i HEAD~10


    Where 10 is the number + 1 of commits you want to squash together. If you want to squash all the commits, then just refer your <first-commit-hash> instead of HEAD~10. Then on the editor you select squash for all the commits you want to group together. You can do search/replace: pick by squash



    Once done, simply push your changes:



    git push --force-with-lease


    I would never recommend to do --force because if another developer has pushed a commit in the meantime you will erase its move. By using --force-with-lease Git will prevent you to push if somebody else has pushed on the top of your last change (see this question for more details).






    share|improve this answer























    • I believe instead of using the <first-commit-hash>, you can use git rebase -i --root to rebase all the way to the initial commit

      – Ru Chern Chong
      Mar 24 at 17:06

















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    I would use git reset --soft



    git reset --soft id-of-first-revision-of-master
    git commit --amend -m "single commit for master"


    Then you can push --force wherever you need that new branch.






    share|improve this answer





























      2














      I would use git reset --soft



      git reset --soft id-of-first-revision-of-master
      git commit --amend -m "single commit for master"


      Then you can push --force wherever you need that new branch.






      share|improve this answer



























        2












        2








        2







        I would use git reset --soft



        git reset --soft id-of-first-revision-of-master
        git commit --amend -m "single commit for master"


        Then you can push --force wherever you need that new branch.






        share|improve this answer















        I would use git reset --soft



        git reset --soft id-of-first-revision-of-master
        git commit --amend -m "single commit for master"


        Then you can push --force wherever you need that new branch.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 24 at 19:00









        RomainValeri

        6,59921435




        6,59921435










        answered Mar 24 at 17:32









        eftshift0eftshift0

        6,72511222




        6,72511222























            1














            You can still modify the history on the upstream by using git push --force-with-lease. However you have to be aware of the consequences.



            Using git push --force will create a parallel tree on your upstream so all the developers may find themselves lost in a legacy branch.



            In order to squash your history, simply do:



            git rebase -i HEAD~10


            Where 10 is the number + 1 of commits you want to squash together. If you want to squash all the commits, then just refer your <first-commit-hash> instead of HEAD~10. Then on the editor you select squash for all the commits you want to group together. You can do search/replace: pick by squash



            Once done, simply push your changes:



            git push --force-with-lease


            I would never recommend to do --force because if another developer has pushed a commit in the meantime you will erase its move. By using --force-with-lease Git will prevent you to push if somebody else has pushed on the top of your last change (see this question for more details).






            share|improve this answer























            • I believe instead of using the <first-commit-hash>, you can use git rebase -i --root to rebase all the way to the initial commit

              – Ru Chern Chong
              Mar 24 at 17:06















            1














            You can still modify the history on the upstream by using git push --force-with-lease. However you have to be aware of the consequences.



            Using git push --force will create a parallel tree on your upstream so all the developers may find themselves lost in a legacy branch.



            In order to squash your history, simply do:



            git rebase -i HEAD~10


            Where 10 is the number + 1 of commits you want to squash together. If you want to squash all the commits, then just refer your <first-commit-hash> instead of HEAD~10. Then on the editor you select squash for all the commits you want to group together. You can do search/replace: pick by squash



            Once done, simply push your changes:



            git push --force-with-lease


            I would never recommend to do --force because if another developer has pushed a commit in the meantime you will erase its move. By using --force-with-lease Git will prevent you to push if somebody else has pushed on the top of your last change (see this question for more details).






            share|improve this answer























            • I believe instead of using the <first-commit-hash>, you can use git rebase -i --root to rebase all the way to the initial commit

              – Ru Chern Chong
              Mar 24 at 17:06













            1












            1








            1







            You can still modify the history on the upstream by using git push --force-with-lease. However you have to be aware of the consequences.



            Using git push --force will create a parallel tree on your upstream so all the developers may find themselves lost in a legacy branch.



            In order to squash your history, simply do:



            git rebase -i HEAD~10


            Where 10 is the number + 1 of commits you want to squash together. If you want to squash all the commits, then just refer your <first-commit-hash> instead of HEAD~10. Then on the editor you select squash for all the commits you want to group together. You can do search/replace: pick by squash



            Once done, simply push your changes:



            git push --force-with-lease


            I would never recommend to do --force because if another developer has pushed a commit in the meantime you will erase its move. By using --force-with-lease Git will prevent you to push if somebody else has pushed on the top of your last change (see this question for more details).






            share|improve this answer













            You can still modify the history on the upstream by using git push --force-with-lease. However you have to be aware of the consequences.



            Using git push --force will create a parallel tree on your upstream so all the developers may find themselves lost in a legacy branch.



            In order to squash your history, simply do:



            git rebase -i HEAD~10


            Where 10 is the number + 1 of commits you want to squash together. If you want to squash all the commits, then just refer your <first-commit-hash> instead of HEAD~10. Then on the editor you select squash for all the commits you want to group together. You can do search/replace: pick by squash



            Once done, simply push your changes:



            git push --force-with-lease


            I would never recommend to do --force because if another developer has pushed a commit in the meantime you will erase its move. By using --force-with-lease Git will prevent you to push if somebody else has pushed on the top of your last change (see this question for more details).







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 24 at 16:39









            nowoxnowox

            7,127946113




            7,127946113












            • I believe instead of using the <first-commit-hash>, you can use git rebase -i --root to rebase all the way to the initial commit

              – Ru Chern Chong
              Mar 24 at 17:06

















            • I believe instead of using the <first-commit-hash>, you can use git rebase -i --root to rebase all the way to the initial commit

              – Ru Chern Chong
              Mar 24 at 17:06
















            I believe instead of using the <first-commit-hash>, you can use git rebase -i --root to rebase all the way to the initial commit

            – Ru Chern Chong
            Mar 24 at 17:06





            I believe instead of using the <first-commit-hash>, you can use git rebase -i --root to rebase all the way to the initial commit

            – Ru Chern Chong
            Mar 24 at 17:06



            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript