Git 选择应暂存的行以进行提交
示例
假设您在一个或多个文件中进行了许多更改,但是从每个文件中您只想提交某些更改,则可以使用以下方法选择所需的更改:
git add -p
要么
git add -p [file]
您的每个更改将单独显示,并且对于每个更改,系统将提示您选择以下选项之一:
y - Yes, add this hunk
n - No, don’t add this hunk
d - No, don’t add this hunk, or any other remaining hunks for this file.
Useful if you’ve already added what you want to, and want to skip over the rest.
s - Split the hunk into smaller hunks, if possible
e - Manually edit the hunk. This is probably the most powerful option.
It will open the hunk in a text editor and you can edit it as needed.这将暂存您选择的文件的各个部分。然后,您可以像这样提交所有分阶段的更改:
git commit -m 'Commit Message'
未暂存或未提交的更改仍将出现在您的工作文件中,并且可以在以后根据需要提交。或者,如果不需要其余更改,可以使用以下方法将其丢弃:
git reset --hard
除了将大更改分解为较小的提交外,此方法还有助于检查您将要提交的内容。通过单独确认每个更改,您将有机会检查自己编写的内容,并可以避免意外上载不需要的代码,例如println/logging语句。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下