我希望能够将带有“squash commit”提交消息的最后 n 个提交压缩为来自 node.js 脚本的单个提交。我知道压缩提交的唯一方法是通过交互式 rebase,有没有办法从 Node 脚本中做到这一点?
例如:
> git log --oneline | head -4
ecce153 Do not change commit
dd831f6 squash commit
c20677a squash commit
86b52fb squash commit
> ./squash.js "New commit made by squashing 3 'squash commit' commits."
ecce153 Do not change commit
as34dwf New commit made by squashing 3 'squash commit' commits.
离开这个 SO 帖子,https://stackoverflow.com/a/5956198/626759 ,我可以很容易地获得交互式 rebase ,但我如何从 Node 脚本中使用它?
谢谢。
最佳答案
你不需要做一个 rebase 来压缩 n 次提交:
git reset HEAD~4
git add .
git commit -m "squashed four commits"
这会备份 HEAD 四个提交,但会保留工作目录中的当前更改,然后在一次提交中添加并提交这些更改。
更短的版本
git reset --soft HEAD~4
git commit -m "squashed four commits"
--soft
也保留索引,因此您不必添加
。
关于git - 可以从 node.js 脚本中压缩 git 提交吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17051891/