[英]Git alias to squash all commits with a particular commit message
I've been using this git-alias which I got from a question on here: 我一直在使用这个git-alias,它是从这里的一个问题中得到的:
wip = !f() { git add -A; git ls-files --deleted -z | xargs -0 git rm; git commit -m "wip";}; f
So now I have a series of n commits, sequentially, which all contain 'wip' on its own as the commit message. 因此,现在我有一系列的n个提交,这些提交都按顺序包含了所有单独的“ wip”作为提交消息。
How do I make a git alias to go about finding the right number of commits back up the tree which contain "wip" and squashes them? 我如何制作git别名来找到正确数量的提交备份到包含“ wip”的树上并进行压榨? Is it actually possible? 真的有可能吗?
You will probably need to interactively rebase
and squash the existing wip
commits. 你可能会需要交互式rebase
和壁球现有的wip
提交。 Since a rebase
with squashes will change history, it makes it difficult (though not impossible) to automate; 由于rebase
用南瓜将改变历史,就很难(虽然不是不可能)自动化; it's best to rebase
on a case-by-case basis. 这是最好的rebase
上的情况下,逐案。 After doing this, you can change your wip
alias to the following: 完成此操作后,您可以将wip
别名更改为以下内容:
git config --global alias.wip '!f() { git add -A; git ls-files --deleted -z | xargs -0 -r git rm; s=`git show --format=%s HEAD | head -1`; if [ "wip" = "$s" ]; then git commit --amend -m "wip"; else git commit -m "wip"; fi;}; f'
This would avoid contiguous wip
commits in your history. 这样可以避免在您的历史记录中出现连续的wip
提交。 The alias is changed from your original alias by using the xargs
-r
option so that If the standard input is completely empty, do not run the command.
通过使用xargs
-r
选项将别名从原始别名更改,以便If the standard input is completely empty, do not run the command.
and if the current HEAD
commit subject is wip
, use commit
's --amend
. 如果当前的HEAD
提交主题是wip
,则使用commit
的--amend
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.