Git add 命令

更新时间: 2019-07-13 17:17

添加文件到暂存区。

语法

git add [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p]
    [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]]
    [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing]
    [--chmod=(+|-)x] [--] [<pathspec>...]

参数

<pathspec>...
    Files to add content from. Fileglobs (e.g.  *.c) can be given to add all matching files. Also a leading directory name (e.g.  dir
    to add dir/file1 and dir/file2) can be given to update the index to match the current state of the directory as a whole (e.g.
    specifying dir will record not just a file dir/file1 modified in the working tree, a file dir/file2 added to the working tree, but
    also a file dir/file3 removed from the working tree. Note that older versions of Git used to ignore removed files; use --no-all
    option if you want to add modified or new files but ignore removed ones.

    For more details about the <pathspec> syntax, see the pathspec entry in gitglossary(7).

-n, --dry-run
    Don't actually add the file(s), just show if they exist and/or will be ignored.

-v, --verbose
    Be verbose.

-f, --force
    Allow adding otherwise ignored files.

-i, --interactive
    Add modified contents in the working tree interactively to the index. Optional path arguments may be supplied to limit operation to
    a subset of the working tree. See "Interactive mode" for details.

-p, --patch
    Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to
    review the difference before adding modified contents to the index.

    This effectively runs add --interactive, but bypasses the initial command menu and directly jumps to the patch subcommand. See
    "Interactive mode" for details.

-e, --edit
    Open the diff vs. the index in an editor and let the user edit it. After the editor was closed, adjust the hunk headers and apply
    the patch to the index.

    The intent of this option is to pick and choose lines of the patch to apply, or even to modify the contents of lines to be staged.
    This can be quicker and more flexible than using the interactive hunk selector. However, it is easy to confuse oneself and create a
    patch that does not apply to the index. See EDITING PATCHES below.

-u, --update
    Update the index just where it already has an entry matching <pathspec>. This removes as well as modifies index entries to match
    the working tree, but adds no new files.

    If no <pathspec> is given when -u option is used, all tracked files in the entire working tree are updated (old versions of Git
    used to limit the update to the current directory and its subdirectories).

-A, --all, --no-ignore-removal
    Update the index not only where the working tree has a file matching <pathspec> but also where the index already has an entry. This
    adds, modifies, and removes index entries to match the working tree.

    If no <pathspec> is given when -A option is used, all files in the entire working tree are updated (old versions of Git used to
    limit the update to the current directory and its subdirectories).

--no-all, --ignore-removal
    Update the index by adding new files that are unknown to the index and files modified in the working tree, but ignore files that
    have been removed from the working tree. This option is a no-op when no <pathspec> is used.

    This option is primarily to help users who are used to older versions of Git, whose "git add <pathspec>..." was a synonym for "git
    add --no-all <pathspec>...", i.e. ignored removed files.

-N, --intent-to-add
    Record only the fact that the path will be added later. An entry for the path is placed in the index with no content. This is
    useful for, among other things, showing the unstaged content of such files with git diff and committing them with git commit -a.

--refresh
    Don't add the file(s), but only refresh their stat() information in the index.

--ignore-errors
    Record only the fact that the path will be added later. An entry for the path is placed in the index with no content. This is
    useful for, among other things, showing the unstaged content of such files with git diff and committing them with git commit -a.

--refresh
    Don't add the file(s), but only refresh their stat() information in the index.

--ignore-errors
    If some files could not be added because of errors indexing them, do not abort the operation, but continue adding the others. The
    command shall still exit with non-zero status. The configuration variable add.ignoreErrors can be set to true to make this the
    default behaviour.

--ignore-missing
    This option can only be used together with --dry-run. By using this option the user can check if any of the given files would be
    ignored, no matter if they are already present in the work tree or not.

--no-warn-embedded-repo
    By default, git add will warn when adding an embedded repository to the index without using git submodule add to create an entry in
    .gitmodules. This option will suppress the warning (e.g., if you are manually performing operations on submodules).

--chmod=(+|-)x
    Override the executable bit of the added files. The executable bit is only changed in the index, the files on disk are left
    unchanged.

--
    This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for
    command-line options).

使用示例

# 添加指定文件到暂存区
$ git add [file1] [file2] ...

# 添加指定目录到暂存区,包括子目录
$ git add [dir]

# 添加当前目录的所有文件到暂存区
$ git add .

# 添加每个变化前,都会要求确认
# 对于同一个文件的多处变化,可以实现分次提交
$ git add -p

查看更多 git add 命令的使用方法,可以使用命令:

git help add
算法设计与应用

算法设计与应用

迈克尔 T. 古德里奇(Michael T. Goodrich)、罗伯特·塔马契亚(Roberto Tamas / 乔海燕、李悫炜、王烁程 / 机械工业出版社 / 2017-11-20 / CNY 139.00

本书全面系统地介绍算法设计和算法应用的各个领域,内容涵盖经典数据结构、经典算法、算法分析方法、算法设计方法以及算法在各个领域的应用,还包含一些高级主题。本书采用应用驱动的方法引入各章内容,内容编排清晰合理,讲解由浅入深。此外,各章都附有巩固练习、创新练习和应用练习三种类型的题目,为读者理解和掌握算法设计和应用提供了很好的素材。 本书可作为高等院校计算机及相关专业“数据结构和算法”课程的本科生......一起来看看 《算法设计与应用》 这本书的介绍吧!

JS 压缩/解压工具

JS 压缩/解压工具

在线压缩/解压 JS 代码

Base64 编码/解码

Base64 编码/解码

Base64 编码/解码

UNIX 时间戳转换

UNIX 时间戳转换

UNIX 时间戳转换