Most efficient way for git commit
How do you stage the changes in git once you have done them in your project?
git add <filename>
OR Worst
git add .
Chances are there are many unwanted changes getting added along with the expected changes.
Here's a better way to stage your expected changes without messing up.
git add -p
Adding -p introduces more elegant way to stage the changes.
This option lets you to choose from each the differences between working tree & index in an interactive way.
You can compare every difference in the file & choose which to include for staging.
In the following example, this is the change I have made.
领英推荐
The storage value is changed from 100Mi to 200Mi
On running git add -p I am presented with a difference as follows.
I want to include the change, so I will hit y for the change to be included in staging.
I do not wish to include the second change. For this I can hit n to not include the hunk in staging.
Once I'm done with choosing all the changes, I can do a git status which will show all the files which are into staging & ready for committed.
Finally I will conclude the commit with
git commit -m "feat(pv): updated storage value"
The --patch option provides a lot of other ways to deal with the changes, which are as follows:
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
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
????????
I'll leave this on you to explore the other options on --patch