diff --git a/git/add.md b/git/add.md new file mode 100644 index 0000000..a7dab3e --- /dev/null +++ b/git/add.md @@ -0,0 +1,30 @@ +# Git Add Methods +## Git Add Sections +### `git add -e` +Select lines of changes interactively. This allows you to stage only specific lines of changes in a file.\ +Pros: More control over what gets staged. +Cons: More manual work, you have to edit the patch file yourself, which can be error-prone and time-consuming. +#### Guidelines: +- staged changes are marked with a "+" at the beginning of the line. +- unstaged changes are marked with a "-" at the beginning of the line. +- unchanged lines are not marked. +- To stage a change, add a "+" at the beginning of the line. +- To unstage a change, add a "-" at the beginning of the line. +- To keep a line unchanged, leave it as is. +### `git add -p` +Select hunks of changes interactively. This allows you to stage only parts of the changes in a file.\ +Pros: Easier to use than the -e method for staging specific parts of changes.\ +Cons: Sometimes split won't work, which will force you to use the -e method. +#### Guidelines +- Run `git add -p ` or `git add -p` to go through patch hunks interactively. +- For each hunk, choose: + - `y` to stage this hunk + - `n` to leave it unstaged + - `s` to split the hunk into smaller parts + - `e` to edit the hunk manually + - `q` to quit and leave remaining hunks unstaged + - `a` to stage this hunk and all remaining hunks + - `d` to leave this hunk and all remaining hunks unstaged +- 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; add `+` to lines to stage, `-` to lines to keep unstaged, then save and close. +- When finished, run `git status` to verify which hunks were staged. \ No newline at end of file