You can use git add --patch <filename>
(or -p
for short), and git will begin to break down your file into what it thinks are sensible "hunks" (portions of the file).
(您可以使用git add --patch <filename>
(或简称-p
),git将开始将您的文件分解为它认为合理的“帅哥”(文件的一部分)。)
It will then prompt you with this question: (然后它会提示您这个问题:)
Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]?
Here is a description of each option:
(以下是每个选项的说明:)
- y stage this hunk for the next commit
(y为下一次提交提供此块)
- n do not stage this hunk for the next commit
(n不要为下次提交暂存此块)
- q quit;
(Q退出;)
do not stage this hunk or any of the remaining hunks (不要把这个大块头或任何剩下的帅哥放在一边)
- a stage this hunk and all later hunks in the file
(这个大块头和后来所有人都在文件中的一个阶段)
- d do not stage this hunk or any of the later hunks in the file
(d不要在文件中放置这个大块或任何后来的黑客)
- g select a hunk to go to
(g选择一个大块去)
- / search for a hunk matching the given regex
(/搜索与给定正则表达式匹配的块)
- j leave this hunk undecided, see next undecided hunk
(j离开这个大块未定,看下一个未定的大块头)
- J leave this hunk undecided, see next hunk
(J离开这个大块未定,看下一个大块头)
- k leave this hunk undecided, see previous undecided hunk
(k离开这个大块未定,看到先前未定的大块头)
- K leave this hunk undecided, see previous hunk
(K离开这个大块未定,看看上一个大块头)
- s split the current hunk into smaller hunks
(而分裂当前大块成更小的厚片)
- e manually edit the current hunk
(e手动编辑当前的大块头)
- ?
(?)
print hunk help (打印大块帮助)
If the file is not in the repository yet, you can first do git add -N <filename>
.
(如果文件尚未存储在存储库中,则可以先执行git add -N <filename>
。)
Afterwards you can go on with git add -p <filename>
. (之后你可以继续使用git add -p <filename>
。)
Afterwards, you can use:
(之后,您可以使用:)
-
git diff --staged
to check that you staged the correct changes (git diff --staged
以检查您是否已暂存正确的更改)
-
git reset -p
to unstage mistakenly added hunks (git reset -p
to unstage错误地添加了帅哥)
-
git commit -v
to view your commit while you edit the commit message. (git commit -v
在编辑提交消息时查看您的提交。)
Note this is far different than the git format-patch
command, whose purpose is to parse commit data into a .patch
files.
(请注意,这与git format-patch
命令有很大不同,后者的目的是将提交数据解析为.patch
文件。)
Reference for future: Git Tools - Interactive Staging
(未来参考: Git工具 - 交互式分段)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…