M
M
My joy2017-07-02 12:56:54
git
My joy, 2017-07-02 12:56:54

Git commit -a works weird?

Hi friends.
Such a problem .. I read that in order not to write before the commit every time git add . you can write the key -a during the commit, sort of like this: But for some reason it works for me every other time. Either untracked files are added, or not. How to understand the logic why this happens? How do you commit?
git commit -a -m 'Comment to commit'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
aRegius, 2017-07-02
@t-alexashka

Hello.
It's just that this shortcut is used in the case of an already existing file in which you make changes. Otherwise, at the very beginning, once you've created a new file , you need to add it in the usual way, via a series of separate add and commit . And after - you can use -a -m .

# создаем новый файл math.txt
echo "# Comment " > math.txt
git add math.txt
git commit -m "This is the first commit."

# Вносим изменения в уже существующий math.txt 
echo "a=1" >> math.txt
git commit -a -m "This is the second commit."

S
Saboteur, 2017-07-02
@saboteur_kiev

If you have created a new file, you must add it to the repository at least once with git add.
git commit -a will commit all files that are already being tracked. In other words:
* New file - git add.
* Changed files - can be done automatically via git commit -a

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question