A
A
Alexfixer2021-12-28 11:14:07
git
Alexfixer, 2021-12-28 11:14:07

Why does a git add command overwrite the line and a new change, and not just add a new change?

Why, after the git add command, the line is overwritten, and not just a new change is added:
1 file changed, 2 insertions (+), 1 deletion (-)

in the git hub it looks like this:
61cac6cb226d8663087431.jpeg

I understand correctly that only the new change should be highlighted in green in the github commit, but for some reason I delete the previous line and also add it in green... Help plz.

ps in the example, the change was - adding a new line with the number 4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Kuznetsov, 2021-12-28
@Alexfixer

See the red sign? This is the reason. In the last line of text, it is desirable to always press Enter to add a newline character. GitHub even specifically tags these places.
61f18e243f64f153432063.png
Lines without a break at the end are bad for Git. Since if you want to add a new line to the file, you will first have to add a hyphen character to the end of the last line, i.e. CHANGE. This change will be visible in history, although formally, it would seem, nothing has changed. It's confusing to see real changes.
So ALWAYS add a break on the last line of code. In most editors, this looks like adding an empty line at the end, but in fact there is no "extra" line, it's a phantom.
If you look through GitHub, then there is no longer an empty line.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question