Compare commits
2 Commits
862b8b2fb0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f167a7c89 | |||
| 0380bb18bb |
35
git/add.md
35
git/add.md
@@ -9,11 +9,15 @@ Cons: More manual work, you have to edit the patch file yourself, which can be e
|
|||||||
- `+` lines: additions in the working tree (will be staged if kept).
|
- `+` lines: additions in the working tree (will be staged if kept).
|
||||||
- `-` lines: deletions in the working tree (will be staged if kept).
|
- `-` lines: deletions in the working tree (will be staged if kept).
|
||||||
- Context lines (no prefix): unchanged lines needed for patch context.
|
- Context lines (no prefix): unchanged lines needed for patch context.
|
||||||
- To stage a change: keep the `+` or `-` line in the patch.
|
- To stage an addition: keep the `+` line in the patch.
|
||||||
- To NOT stage a change: **delete** the `+` or `-` line from the patch.
|
- To NOT stage an addition: **delete** the `+` line from the patch.
|
||||||
|
- To stage a deletion: keep the `-` line in the patch.
|
||||||
|
- To NOT stage a deletion: **convert the `-` to a space**.
|
||||||
|
- For modified content (shown with `-` lines followed by `+` lines):
|
||||||
|
- To NOT stage the modification: convert the `-` lines to spaces and remove the `+` lines.
|
||||||
|
- Note: modifying only half of the pair may cause confusing changes to the index.
|
||||||
- To keep a line unchanged: leave context lines as-is.
|
- To keep a line unchanged: leave context lines as-is.
|
||||||
- **Never change `+` or `-` to spaces or vice versa** — this breaks the patch format and causes "patch does not apply" errors.
|
- If you want to decline the operation entirely, delete all lines of the patch.
|
||||||
- **To remove an added line (`+`) from being staged, delete the entire line.**
|
|
||||||
- If you break the patch, run `git checkout -- <file>` to undo, then run `git add -e` again.
|
- If you break the patch, run `git checkout -- <file>` to undo, then run `git add -e` again.
|
||||||
## Git Add Hunks
|
## Git Add Hunks
|
||||||
### `git add -p`
|
### `git add -p`
|
||||||
@@ -23,13 +27,20 @@ Cons: Sometimes split won't work, which will force you to use the -e method.
|
|||||||
#### Guidelines
|
#### Guidelines
|
||||||
- Run `git add -p <file>` or `git add -p` to go through patch hunks interactively.
|
- Run `git add -p <file>` or `git add -p` to go through patch hunks interactively.
|
||||||
- For each hunk, choose:
|
- For each hunk, choose:
|
||||||
- `y` to stage this hunk
|
- `y` to stage the hunk
|
||||||
- `n` to leave it unstaged
|
- `n` to not stage the hunk
|
||||||
- `s` to split the hunk into smaller parts
|
- `q` to quit; do not stage the hunk or any remaining ones
|
||||||
- `e` to edit the hunk manually
|
- `a` to stage the hunk and all later hunks in the file
|
||||||
- `q` to quit and leave remaining hunks unstaged
|
- `d` to not stage the hunk or any later hunks in the file
|
||||||
- `a` to stage this hunk and all remaining hunks
|
- `g` to select a hunk to go to
|
||||||
- `d` to leave this hunk and all remaining hunks unstaged
|
- `/` to search for a hunk matching the given regex
|
||||||
|
- `j` to go to the next hunk
|
||||||
|
- `J` to go to the previous hunk
|
||||||
|
- `k` to go to the previous hunk
|
||||||
|
- `K` to go to the previous undecided hunk
|
||||||
|
- `s` to split the current hunk into smaller ones
|
||||||
|
- `e` to manually edit the current hunk
|
||||||
|
- `?` to print help
|
||||||
- If you choose `s`, Git will attempt to split the hunk into smaller hunks so you can stage a smaller section.
|
- If you choose `s`, Git will attempt to split the hunk into smaller hunks so you can stage a smaller section.
|
||||||
- If you choose `e`, Git opens the patch in a temporary editor; delete `+` or `-` lines you do NOT want staged, then save and close.
|
- If you choose `e`, Git opens the patch in a temporary editor; delete `+` lines you do NOT want staged and convert `-` lines to spaces to prevent staging their deletion, then save and close.
|
||||||
- When finished, run `git status` to verify which hunks were staged.
|
- When finished, run `git status` to verify which hunks were staged.
|
||||||
Reference in New Issue
Block a user