Git

Git add

2018-11-06  本文已影响10人  JaedenKil

Usually, these operations can be used to do git add rapidly.

git add -A
git add .
git add -u

But there are some minor differences:
git add -A stages all changes.
git add . stages new files and modifications, without deletions.
git add -u stages modifications and deletions, without new files.
So git add -A is equivalent to git add .; git add -u .

git init
echo Change me > change-me
echo Delete me > delete-me
git add change-me delete-me
git commit -m initial

echo OK >> change-me
rm delete-me
echo Add me > add-me

git status
# Changed but not updated:
#   modified:   change-me
#   deleted:    delete-me
# Untracked files:
#   add-me

git add .
git status

# Changes to be committed:
#   new file:   add-me
#   modified:   change-me
# Changed but not updated:
#   deleted:    delete-me

git reset

git add -u
git status

# Changes to be committed:
#   modified:   change-me
#   deleted:    delete-me
# Untracked files:
#   add-me

git reset

git add -A
git status

# Changes to be committed:
#   new file:   add-me
#   modified:   change-me
#   deleted:    delete-me

git add -u is useful after editing README.md with a text editor. Some editors may do backup automatically after editing some files with the editor.
For instance:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   README.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        README.md.bak

no changes added to commit (use "git add" and/or "git commit -a")
$ git add -u // Will stage the already staged file README.md changes, and ignore the unstaged file README.md.bak changes
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   README.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        README.md.bak

Refer to here.

上一篇下一篇

猜你喜欢

热点阅读