git squash last n在没有交互式rebase的情况下提交

时间:2017-05-12 18:45:33

标签: git

我做了很多压缩,我只关心第一次提交的提交消息。目前我使用着名的git rebase -i head~n,这使得这个浪费时间的多步骤过程。我一直在阅读其他回复,但没有一个能够满足我的需求。

基本上我试图用一个命令实现以下​​git交互式rebase编辑器在保存后将实现的内容(例如:最后4次提交):

#!/bin/sh
#

# get number of commits to squash
n=$1

# validate that n is an integer
regex="^[0-9]+$"
if ! [[ $n =~ $regex ]]; then
    echo "error: Squash count must be an integer."
    exit 0
fi

# get the nth commit message
skip=$(( $n - 1 ))
nthMessage=$(git log --skip=$skip --max-count=1 --pretty=%B)

# do the squash
git reset --soft HEAD~$n
git commit -m "$nthMessage"

exit 0

答案:其他帖子中的答案都没有完全符合我的要求,所以即使这被标记为重复,这里的解决方案结合了链接帖子中的一些答案。

主要区别在于我只想保留第n个​​提交的消息。

1。为压缩创建脚本(squash.sh)

squash = !sh -c '<path-to>/squash.sh $1' -

2。在.gitconfig中添加别名

git squash 4

第3。压扁(例如:最后4次提交):

// Mutation
mutation CreateProduct ($input: CreateProductInput!) {
  createProduct(input: $input) {
    changedProduct {
      id
      name
      price {
        id
        amount
      }
    }
  }
}

// Variables
{
  input: {
    name: "My First Product",
    price: {
      amount: 1000
    }
  }
}

0 个答案:

没有答案
相关问题