The Add Interactive Command
Explore how to use git add interactive mode to selectively stage parts of your code changes. Understand staging, hunks, and splitting changes to organize commits effectively and avoid including unwanted lines in your repository history.
We'll cover the following...
We'll cover the following...
The git add -i command
Let’s demonstrate how you might want to use this with a simple example:
1 mkdir lgthw_add_i
2 cd lgthw_add_i
3 git init
4 echo 'This is file1' > file1
5 echo 'This is file2' > file2
6 git add file1 file2
7 git commit -am 'files added'
8 cat > file1 << END
9 > Good change
10 > This is file1
11 > Experimental change
12 > END
13 cat > file2 << END
14 > All good
15 > This is file2
16 > END
Now run the following, and input the characters (or just “enter”/“return”) at the appropriate points:
17 git add -i
18 What now> p
19 Patch update>> 1
Note that in the next line, you only need to input the “enter”/“return” key. Just hit “return”.
20 Patch update>>
21 Stage this hunk [y,n,q,a,d,/,s,e,?]? s
22 Stage this hunk [y,n,q,a,d,/,s,e,?]? y
23 Stage this ...