美文网首页
Git合并本地更改(Squash)

Git合并本地更改(Squash)

作者: 听松客未眠 | 来源:发表于2019-12-13 09:18 被阅读0次

    很多时候,把本地多个Git commit合并为一个再push,有很大的优势。这个操作在Git中被称为Squash。

    示例如下:

    # Reset the current branch to the commit just before the last 12:
    git reset --hard HEAD~12
    
    # HEAD@{1} is where the branch was just before the previous command.
    # This command sets the state of the index to be as it would just
    # after a merge from that commit:
    git merge --squash HEAD@{1}
    
    # Commit those squashed changes.  The commit message will be helpfully
    # prepopulated with the commit messages of all the squashed commits:
    git commit
    

    参考文献

    [1] https://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git

    相关文章

      网友评论

          本文标题:Git合并本地更改(Squash)

          本文链接:https://www.haomeiwen.com/subject/npoxnctx.html