开发者

Committing hunks from inside of git add -i?

开发者 https://www.devze.com 2022-12-29 17:05 出处:网络
Is this possible? It would be nice if I didn\'t have to switch back and forth between git-add -i and git commit when breaking apart hunks into different commits. Is th开发者_如何学JAVAere a better way

Is this possible? It would be nice if I didn't have to switch back and forth between git-add -i and git commit when breaking apart hunks into different commits. Is th开发者_如何学JAVAere a better way to do this? Or am I doing something wrong?


As described in the git book, a simple git commit is still required after a git add --interactive session.
(With the following caveat:

Remember not to run 'git commit -a', which will blow away all the careful changes you've just made and simply commit everything )

Note: maybe git add -p (--patch) will be a little more convenient:

Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.

This effectively runs add --interactive, but bypasses the initial command menu and directly jumps to the patch subcommand.


Bonus, with Git 2.24 (Q4 2019), "git add -i" has been taught to show the total number of hunks and the hunks that has been processed so far when showing prompts.

See commit 8085050 (30 Sep 2019) by Kunal Tyagi (kunaltyagi).
(Merged by Junio C Hamano -- gitster -- in commit f0d407e, 11 Oct 2019)

add -i: show progress counter in the prompt

So, while you still need a separate commit step, at least you how far along you are during the completion of the interactive/patch git add session.

0

精彩评论

暂无评论...
验证码 换一张
取 消