Skip to content

Instantly share code, notes, and snippets.

@gitjs77
Forked from remboo/comparing-git-add.md
Created August 7, 2017 12:26
Show Gist options
  • Save gitjs77/55af28e9b0916e03b0183d39f4ae81c5 to your computer and use it in GitHub Desktop.
Save gitjs77/55af28e9b0916e03b0183d39f4ae81c5 to your computer and use it in GitHub Desktop.
Comparing 'git add' variations

git add . vs git add -A vs git add -u vs git commit -a vs git add --ignore-removal

git add . , git add -A stage all files, including new files (which git commit -a misses) and deleted files.

The difference is that git add -A also stages files in higher directories that still belong to the same git repository. Here's an example:

/my-repo
  .git/
  subfolder/
    nestedfile.txt
  rootfile.txt

If your current working directory is /my-repo, and that's the root of this git repo (thus the .git/ folder), these two commands will do the same thing.

But if you rm rootfile.txt, then cd subfolder, git add . will not stage the change that ../rootfile.txt has been deleted, because git add . only affects the current directory and subdirectories. git add -A, on the other hand, will stage this commit.

Примечание:

git add -A - сохраняет изменения всех файлов иерархии  

git add . - сохраняет изменения всех файлов текущей директории и всех подкаталогов, но не файлов подкаталогов.

В примере мы удалили файл в директории, поднялись на уровень выше. Удаление файла не будет фиксироваться с помощью git add .

git commit -a - можно сразу делать коммиты без git add , но не будут добавляться созданные(новые) файлы в коммит.

git add -u - не сохраняет новые файлы

git add --ignore-removal - не сохраняет удаленные файлы

Вывод:

git add -A - самый универсальный способ для добавления всех файлов для коммита.

alt text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment