简体   繁体   English

Git:自动修复功能分支中的提交

[英]Git: auto-fixup a commit in a feature branch

When I am done with a feature, often what I would like is to auto-fixup a commit followed by a force-push to a remote origin before a merge to master.当我完成一个功能时,通常我想要的是自动修复提交,然后在合并到 master 之前强制推送到远程源。

I end up rebasing on top of master so I can fixup a commit, because I found a tiny thing I want to change and I don't want that change as a separate commit.我最终以 master 为基础,因此我可以修复提交,因为我发现了一个我想要更改的小东西,我不希望将该更改作为单独的提交。 So I rebase interactively, I fixup the last commit, then I force push.所以我以交互方式变基,修复最后一次提交,然后强制推送。 Is there a way to do that in one step?有没有办法一步做到这一点?

Assuming you want to fixup the last commit, you could just amend that commit.假设您想修复最后一次提交,您可以修改该提交。 After authoring your changes, just issue:创作您的更改后,只需发出:

$ git commit -a --amend --no-edit

You'll still have to force-push, though.但是,您仍然必须强制推动。

Here's a breakdown of git commit options used above:这是上面使用的git commit选项的细分:

-a, --all: 
Tell the command to automatically stage files that have been modified and 
deleted, but new files you have not told Git about are not affected.

--amend: 
Replace the tip of the current branch by creating a new commit.

--no-edit: 
Use the selected commit message without launching an editor. 
For example, `git commit --amend --no-edit` amends a commit without changing 
its commit message.

You can save the step of editing the list of commits manually in rebase -i using git commit --fixup <commit> when making your fixup commit. git commit --fixup <commit>时,您可以使用git commit --fixup <commit>rebase -i保存手动编辑提交列表的步骤。 Then, if rebase.autoSquash is set to true, git rebase -i will automatically turn the line containing this commit into a fixup line right below the commit to fix.然后,如果rebase.autoSquash被设置为真, git rebase -i将自动开启包含此提交到行fixup线正下方的承诺修复。

git commit -a --amend --no-edit && git push -f

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM