How to partially stage files
GIT has a wonderful idea that is known as the staging area. The stage area is the place where you prepare the files that are going to be on your next commit. Sometimes you want to add only one specific part of some files.
You can use one of the following commands. These commands with their options will break down your files into smaller portions named hunks.
git add -p
You can use git add --patch <filename>
as well. When you run this, It will be prompted to you with the options below: I will explain only a few of them.
Stage this hunk? [y,n,q,a,d,/,j,J,g,s,e,?]
q - Quit; do not stage this hunk or any of the remaining hunks
y - Yes, add this hunk
n - No, don't add this hunk
s - Split the hunk into smaller hunks
/ - Search for a hunk matching the given regex
? - Print hunk help
This is really great for me because it helps me write code as much as I want and while doing that, I can still achieve one of the core GIT rules.
Each commit should represent the only one logical change
This command is like passing the --interactive
argument but without the initial command menu. It jumps directly to the patch subcommand.
References
Subscribe to my newsletter
Read articles from Erdal TAŞKESEN directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Erdal TAŞKESEN
Erdal TAŞKESEN
Hey, y’all 🖖🏽 I am a passionate self-taught developer, open-source advocate, and tech enthusiast with a hands-on approach to problem-solving and an unending thirst for knowledge. Anything and everything classified as technology fascinate me.