2017-03-02 45 views
0

通常我想压缩垃圾分支中的几十个提交,以在临时服务器上测试出所有内容。特别是在使用具有问题自动关闭功能(如bitbucket)的问题跟踪器时 - 我不想关闭当时提交消息中提到的问题,所以我需要压扁。简单的方法来压缩多个提交?

必须有一些事情比单独更改rebase或单独更改每一条线更简单,或者必须知道多少提交前是壁球的目标。

像“壁球的一切,直到这犯了哈希XXXXXX”

回答

3

是的,当你使用互动模式重订,你可以通过标记它们壁球提交被压扁。参见:

  1. https://robots.thoughtbot.com/git-interactive-rebase-squash-amend-rewriting-history#squash-commits-together
  2. http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

您也可以尝试git merge --squash这是一种更直接的方式和东西,你正在寻找 - https://stackoverflow.com/a/5190323/7274758

让我们说你有以下提交集合

O - O - L1 - F1 - F2 - F3a - F3b - F4 - .... - FN 
     |  |        \_ master, HEAD 
     |  \_ Fix for Issue 1 and so on. 
     | 
     \_ Last Tested. You would like to squash all from this point 
  1. 重置头L1 git reset --hard L1

    O - O - L1 - F1 - F2 - F3a - F3b - F4 - .... - FN 
         |  |         
         |  \_ Fix for Issue 1 and so on. 
         | 
         \_ (Last Tested), master, HEAD 
    
  2. 现在壁球一切,直到前面的头(即FN)git merge --squash [email protected]{1}

    O - O - L1 - F1 - F2 - F3a - F3b - F4 - .... - FN 
         | \ 
         | \_ 0 
         | 
         \_ (Last Tested), master, HEAD 
    
  3. 执行提交 - git commit这将承诺从F1的所有更改到FN(SF1_FN)

    O - O - L1 - SF1_FN 
          | 
          \_ master, HEAD 
    
0
git checkout --orphan wip 
git commit 

如果你只是测试内容,你不需要祖先。

2

最自动的方法是使用git merge --squash。你是否应该使用Libin Varghese的答案或者这个答案可能取决于你是否打算保留原始提交。如果不是,他说明的是直截了当的。但如果是这样......

如果你有

A --- B --- C --- D <--(branch) 

,你想壁球BCD,你可以做

git checkout B^ 
git checkout -b squashed_branch 
git merge --squash branch 
git commit 

,现在你必须

A --- B --- C --- D <--(branch) 
    \ 
    BCD <--(squashed_branch) 
+0

希望我能接受这两个答案,但是,我想保留原始提交。我想@Libin Varghese也考虑过这个,并且意在在分支到垃圾分支之后做些什么。 – rzb

相关问题