Squash my last X commits together using Git

前端 未结 30 3472
醉酒成梦
醉酒成梦 2020-11-21 05:17

How can I squash my last X commits together into one commit using Git?

30条回答
  •  情深已故
    2020-11-21 05:52

    If you are on a remote branch(called feature-branch) cloned from a Golden Repository(golden_repo_name), then here's the technique to squash your commits into one:

    1. Checkout the golden repo

      git checkout golden_repo_name
      
    2. Create a new branch from it(golden repo) as follows

      git checkout -b dev-branch
      
    3. Squash merge with your local branch that you have already

      git merge --squash feature-branch
      
    4. Commit your changes (this will be the only commit that goes in dev-branch)

      git commit -m "My feature complete"
      
    5. Push the branch to your local repository

      git push origin dev-branch
      

提交回复
热议问题