让我们说你的例子。css看起来像这样:
.classname {
width: 440px;
}
/*#field_teacher_id {
display: block;
} */
form.table-form #field_teacher + label,
form.table-form #field_producer_distributor + label {
width: 300px;
}
.another {
width: 420px;
}
现在让我们改变中间块中的样式选择器,同时删除一些我们不再需要的旧的注释样式。
.classname {
width: 440px;
}
#user-register form.table-form .field-type-checkbox label {
width: 300px;
}
.another {
width: 420px;
}
这很简单,现在让我们开始吧。但是等等,我想在版本控制中维护更改的逻辑分离,以便进行简单的分步代码审查,这样我和我的团队就可以轻松地搜索提交历史以获取细节。
删除旧代码在逻辑上与其他样式选择器更改是分开的。我们将需要两次不同的提交,所以让我们为一个补丁添加大块。
git add --patch
Diff——git a/example.css b/example.css
指数426449 d . .50 ecff9 100644
——/ example.css
+ + + b / example.css
@@ -2,12 +2,7 @@
宽度:440 px;
}
- / * # field_teacher_id {
- display: block;
-} * /
-
—构成。表格形式#field_teacher +标签,
—构成。Table-form #field_producer_distributor + label {
+ #用户注册表单。表-form .field-type-checkbox标签{
宽度:300 px;
}
舞台这个大块头[y,n,q,a,d,/,e,?]?
哎呀,看起来变化太接近了,所以git把它们组合在一起了。
即使尝试通过按s来分割它也会有相同的结果,因为分割的粒度不足以满足我们的精度更改。为了git能够自动分割补丁,更改的行之间需要未更改的行。
那么,让我们手动编辑它,按下e
Stage this hunk [y,n,q,a,d,/,e,?]? e
Git将在我们选择的编辑器中打开补丁。
# Manual hunk edit mode -- see bottom for a quick guide
@@ -2,12 +2,7 @@
width: 440px;
}
-/*#field_teacher_id {
- display: block;
-} */
-
-form.table-form #field_teacher + label,
-form.table-form #field_producer_distributor + label {
+#user-register form.table-form .field-type-checkbox label {
width: 300px;
}
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
#
# If the patch applies cleanly, the edited hunk will immediately be
# marked for staging. If it does not apply cleanly, you will be given
# an opportunity to edit again. If all lines of the hunk are removed,
# then the edit is aborted and the hunk is left unchanged.
让我们回顾一下目标:
我如何才能添加CSS注释删除只到下一次提交?
我们想把它分成两个提交:
The first commit involves deleting some lines (comment removal).
To remove the commented lines, just leave them alone, they are already marked to track the deletions in version control just like we want.
-/*#field_teacher_id {
- display: block;
-} */
The second commit is a change, which is tracked by recording both deletions and additions:
Deletions (old selector lines removed)
To keep the old selector lines (do not delete them during this commit), we want...
To remove '-' lines, make them ' '
...which literally means replacing the minus - signs with a space character.
So these three lines...
-
-form.table-form #field_teacher + label,
-form.table-form #field_producer_distributor + label {
...will become (notice the single space at the first of all 3 lines):
form.table-form #field_teacher + label,
form.table-form #field_producer_distributor + label {
Additions (new selector line added)
To not pay attention to the new selector line added during this commit, we want...
To remove '+' lines, delete them.
...which literally means to delete the whole line:
+#user-register form.table-form .field-type-checkbox label {
(Bonus: If you happen to be using vim as your editor, press dd to delete a line. Nano users press Ctrl+K)
当你保存时,你的编辑器应该是这样的:
# Manual hunk edit mode -- see bottom for a quick guide
@@ -2,12 +2,7 @@
width: 440px;
}
-/*#field_teacher_id {
- display: block;
-} */
form.table-form #field_teacher + label,
form.table-form #field_producer_distributor + label {
width: 300px;
}
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
#
# If the patch applies cleanly, the edited hunk will immediately be
# marked for staging. If it does not apply cleanly, you will be given
# an opportunity to edit again. If all lines of the hunk are removed,
# then the edit is aborted and the hunk is left unchanged.
现在让我们开始吧。
git commit -m "remove old code"
为了确保,让我们看看上次提交的变化。
git show
提交572年ecbc7beecca495c8965ce54fbccabdd085112
作者:杰夫·帕克特<jeff@jeffpuckett.com>
日期:2016年6月11日星期六17:06:48 -0500
删除旧代码
Diff——git a/example.css b/example.css
指数426449 d . .d04c832 100644
——/ example.css
+ + + b / example.css
@@ -2,9 +2,6 @@
宽度:440 px;
}
- / * # field_teacher_id {
- display: block;
-} * /
的形式。表格形式#field_teacher +标签,
的形式。Table-form #field_producer_distributor + label {
完美——您可以看到原子提交中只包含了删除。现在让我们完成工作,把剩下的交给他们。
git add .
git commit -m "change selectors"
git show
提交83年ec3c16b73bca799e4ed525148cf303e0bd39f9
作者:杰夫·帕克特<jeff@jeffpuckett.com>
日期:2016年6月11日星期六17:09:12 -0500
改变选择器
Diff——git a/example.css b/example.css
指数d04c832 . .50 ecff9 100644
——/ example.css
+ + + b / example.css
@@ -2,9 +2,7 @@
宽度:440 px;
}
-
—构成。表格形式#field_teacher +标签,
—构成。Table-form #field_producer_distributor + label {
+ #用户注册表单。表-form .field-type-checkbox标签{
宽度:300 px;
}
最后,您可以看到最后一次提交只包括选择器更改。