Interactive staging is a neat feature in Git that lets you be selective about which file changes to be staged.
Prerequisites
- Git
Solution
Step 1. Go to your Git working directory, and before you stage any file(s), use:
git add -p <filename_to_be_picky_about>
or just
git add -p
Step 2. Now, Git will ask for your input (interactive mode) about which changes need to be staged.
(1/1) Stage this hunk [y,n,q,a,d,e,?]?
Step 3. Type ?
and hit Enter to see what these options mean. To save you some time though:
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any of the later hunks in the file
e - manually edit the current hunk
? - print help
Conclusion
To find more neat Git commands and hacks, simply browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.