I had the following code. (I added line numbers for clarification)
(1) if (foo1)
(2) {
(3) some code 1
(4) }
I changed the if condition to if (foo1 || bar1)
. I also added similar code above, what results in
(1) if (foo0 || bar0)
(2) {
(3) some code 0
(4) }
(5)
(6) if (foo1 || bar1)
(7) {
(8) some code 1
(9) }
I use git. The Visual Studio compare tool now thinks that I replaced if (foo1)
with if (foo0 || bar0)
and that I added the rest, including if (foo1 || bar1)
, as new code.
(1) if (foo1) (1) if (foo0 || bar0)
(-) (2) {
(-) (3) some code 0
(-) (4) }
(-) (5)
(-) (6) if (foo1 || bar1)
This is a problem, because I want to separate the changes into 2 commits. But I cannot stage only the change of the if condition, because the compare tool does not see, that it is a change. What could I do? Is it e. g. possible to manually link line 1 with line 6?
2
Answers
It’s not possible to link line 1 to 6.
I would suggest you separate them into two commits like the following:
Alternatively, instead of the first commit you can perform git add to stage it and this will give you the ability to compare too.
You can use patch commits:
git commit --patch
, this will run an interactive commits
)y
) and don’t stage the second (n
)git add .
andgit commit
for the second commitIf you run
?
during the patch you can see what all the options do, like this picture