![A stick figure smiling](/images/welcome.jpg)
If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!
![Image of a comic. To read the full HTML alt text, click "read the transcript".](/images/uploads/git-add-p.png)
read the transcript!
git add -p
lets you stage some changes and not others
I use this if I want to commit my real changes, but not the random debugging code I added.
(this is one of the tasks GUIs and IDEs are best at, but I always use git add -p
anyway)
what the interface looks like
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
"name": "homepage",
- "version": "1.0.0",
+ "version": "1.0.1",
"devDependencies": {
- "dart-sass": "^1.25.0"
+ "dart-sass": "^1.26.0",
(1/1) Stage this hunk
[y,n,q,a,d, s,e,?]?
package.json is the filename
lines 4-9 are the diff
[y,n,q,a,d, s,e,?]
is your choice
y(es)/n(o)/q(uit)
y means “stage this change”
n means “don’t”
q quits, keeping what you did so far. pretty straightforward.
how to check your work
git diff --cached
will show your staged changes
s: split into two parts
s will split a diff into smaller diffs you can say y or n to individually, like this:
+++ b/package.json
@@ -1,7 +1,7 @@
- "version": "1.0.0",
+ "version": "1.0.1",
"devDependencies": {
BUT! This only works if there’s a newline between the two parts.
how to split a diff if there’s no newline
You can use the e (“edit”) option to edit the diff manually: - to remove a - line, replace “-” with a space - to remove a + line, delete the whole line
version 1:
"name": "homepage",
- "version": "1.0.0",
- "devDependencies": { "version": "1.0.1",
+ "devDependenciezzz'
version 2:
"name": "homepage",
- "version": "1.0.0",
+ "version": "1.0.1",
[space] "devDependencies":
[space]
(or you can just say ‘n’ and edit your code! that’s what I do!)
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!