当前位置:   article > 正文

Git add 命令详解_gitadd

gitadd

这是官方给出的详解(英文): https://git-scm.com/docs/git-add

当我们调用·git add -h可以查看相关帮助。
这里写图片描述

首先git add命令使用当前在工作树下的内容更新索引(index),准备这个内容暂存为了下次的提交(commit)。它通常将当前现有路径作为一个整体的内容添加,但通过某些选项也可以对工作树中的应用文件所做更改的部分进行添加,或删除那些不存在工作树下的路径。

-n
–dry-run

Don’t actually add the file(s), just show if they exist and/or will be ignored.
不实际添加文件,仅仅是展示他们是否存在或者将被忽略。
  • 1
  • 2

-v
–verbose

Be verbose.
详细的。
  • 1
  • 2

-f
–force

Allow adding otherwise ignored files.
允许添加其他被忽略的文件。
  • 1
  • 2

-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.
交互的向索引中添加工作树中的修改内容。提供可选的路径参数来限制操作工作树中的一个子集。查看“互动模式”获取详细信息。
  • 1
  • 2

-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.
  • 1
  • 2
  • 3

-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.
  • 1
  • 2
  • 3

-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).
  • 1
  • 2
  • 3

-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).
  • 1
  • 2
  • 3

–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.
  • 1
  • 2
  • 3

-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.
  • 1

–refresh

Don’t add the file(s), but only refresh their stat() information in the index.
  • 1

–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.
  • 1

–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.
  • 1

–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).
  • 1

–renormalize

Apply the "clean" process freshly to all tracked files to forcibly add them again to the index. This is useful after changing core.autocrlf configuration or the text attribute in order to correct files added with wrong CRLF/LF line endings. This option implies -u.
  • 1

–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).
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/903018
推荐阅读
相关标签
  

闽ICP备14008679号