GIT帮助文档翻译之git-add

        本人因英语水平有限, 加之对git不是十分熟悉, 所以会有很多翻译不当的地方, 希望大家批评指正

翻译附英文, 拿捏不准的地方都用红字标示.希望大家多提修改意见.


NAME

    git-add - 将文件内容添加到暂存区.

 

                git-add - Add file contents to theindex

 

SYNOPSIS

                git add [-n] [-v] [--force | -f][--interactive | -i] [--patch | -p]

                        [--edit | -e] [--all | [--update | -u]][--intent-to-add | -N]

                        [--refresh] [--ignore-errors][--ignore-missing] [--]

                        [...]

 

DESCRIPTION

                这个命令使用工作树中的内容更新暂存区, 为下一步的提交将内容暂存起来.

                通常把现有路径的内容作为一个整体添加, 但是如果使用一些选项, 也可以

                只对工作树中修改的部分文件应用添加操作, 或者删除工作树中不再存在的

                路径.

 

                This command updates the index using thecurrent content found in the

                working tree, to prepare the contentstaged for the next commit. It

                typically adds the current content ofexisting paths as a whole, but

                with some options it can also be usedto add content with only part of

                the changes made to the working treefiles applied, or remove paths

                that do not exist in the working treeanymore.

 

                "暂存区"保存了工作树中内容的一个快照,这个快照也被当做下一次提交的内容,

                因此, 对工作目录中做任何更改之后, 并且在执行commit命令之前, 必须使用

               add命令将任何新增加的或者被修改过的文件添加到暂存区.

 

                The "index" holds a snapshotof the content of the working tree, and it

                is this snapshot that is taken as thecontents of the next commit. Thus

                after making any changes to theworking directory, and before running

                the commit command, you must use theadd command to add any new or

                modified files to the index.

 

                在一个提交之前, 这个命令可以被执行多次, 当执行add命令时, 它只添加指定

                的文件的内容; 如果想把随后的更改提交到下一次提交中, 那么必须再次执行

                git add把新的内容添加到暂存区.

 

                This command can be performed multipletimes before a commit. It only

                adds the content of the specifiedfile(s) at the time the add command

                is run; if you want subsequent changesincluded in the next commit,

                then you must run git add again to addthe new content to the index.

 

                git status命令可以获得有修改并且被暂存用于下一次提交的文件变更的摘要.

 

                The git status command can be used toobtain a summary of which files

                have changes that are staged for thenext commit.

 

                默认情况git add命令不会添加被忽略的文件, 如果任何被忽略的文件明确地

                出现在命令行中, git add将会失败, 并列出已忽略文件.如果递归地在目录中

                有忽略文件或者使用git的通配符匹配了忽略文件(用引号把通配符引起来)

                将会安静地忽略掉

 

                The git add command will not addignored files by default. If any

                ignored files were explicitly specifiedon the command line, git add

                will fail with a list of ignoredfiles. Ignored files reached by

                directory recursion or filenameglobbing performed by Git (quote your

                globs before the shell) will besilently ignored. The git add command

                can be used to add ignored files withthe -f (force) option.

 

                请查看git-commit(1)中一种替代的内容提交的方式.

 

                Please see git-commit(1) foralternative ways to add content to a

                commit.

 

OPTIONS

            ...

                添加内容的来源(Files to add content from). 文件通配符(e.g. *.c)

                和前导目录名(e.g.  dir to add dir/file1and dir/file2)都可以用在

                要添加的文件上.

 

                Files to add content from. Fileglobs(e.g.  *.c) can be given to

                add all matching files. Also a leadingdirectory name (e.g.  dir to

                adddir/file1 and dir/file2) can be given to add all files in the

                directory, recursively.

 

                -n, --dry-run

                    并不真正的添加文件, 仅仅查看它们是否会被添加还是会被忽略.

 

                    Don’t actually add the file(s), just showif they exist and/or will

                    be ignored.

 

                -v, --verbose

                    显示详细信息.

 

                    Be verbose.

 

                -f, --force

                    允许添加被忽略的文件.

 

                    Allow adding otherwise ignored files.

 

                -i, --interactive

                    交互式地将工作树修改的内容添加到暂存区. 可以提供一个可选的路径参数,

                    通过这个参数可以只操作工作树中的所有修改中的一部分. 参阅

                    "Interactive mode"获取更详细的信息.

 

                    Add modified contents in the working treeinteractively to the

                    index. Optional path arguments may besupplied to limit operation

                    to a subset of the working tree. See “Interactivemode” for

                    details.

 

                -p, --patch

                    交互式地决定是否将版本库与工作树之间的差异添加到暂存区. 给使用者在

                    把修改提交到暂存区之前一个浏览差异的机会.

 

                    Interactively choose hunks of patchbetween the index and the work

                    treeand add them to the index. This gives the user a chance to

                    reviewthe difference before adding modified contents to the index.

 

                    This effectively runs add --interactive, butbypasses the initial

                    command menu and directly jumps to the patchsubcommand. See

                   “Interactivemode” for details.

 

                -e,--edit

                    打开diff对比. 把暂存区与工作树中的差异显示在编辑器里, 让用户编辑.

                    当编辑器关闭时, 调整(hunk headers) 并将补丁提交到暂存区.

 

                    Openthe diff vs. the index in an editor and let the user edit it.

                    Afterthe editor was closed, adjust the hunk headers and apply the

                    patch to the index.

 

                    本选项的意图在于挑选补丁中的某些行进行提交, 甚至可以修改要被暂存的

                    行. 这种方法比起使用交互式的选择块更加快速和灵活. 然后, 它也

                    容易让人迷惑, 创建了一个没有提交到暂存区的补丁.参阅以下的EDITING PATCHES

 

                    Theintent of this option is to pick and choose lines of the patch

                    toapply, or even to modify the contents of lines to be staged.

                    Thiscan be quicker and more flexible than using the interactive

                    hunkselector. However, it is easy to confuse oneself and create a

                    patchthat does not apply to the index. See EDITING PATCHES below.

 

 

               -u, --update

                   只适用于已经在暂存区被跟踪的而不是在工作树中的文件. 也就意味着他永远

                  不会暂存新增的文件, 但是如果文件已经被版本库跟踪, 并且已经被修改或者

                  被从工作树中删除的话, 那么它可以将修改提交到暂存区.

 

                    Onlymatch against already tracked files in the index

                    rather than the working tree. Thatmeans that it will never stage

                    new files, but that it will stagemodified new contents of tracked

                    files and that it will remove filesfrom the index if the

                    corresponding files in the working tree havebeen removed.

 

                    如果没有提供, 默认为".".也就是说, 把当前目录及其子目录中

                    所有被跟踪文件的修改提交到暂存区.

 

                    If no is given, default to"."; in other words,

                    update all tracked files in thecurrent directory and its

                    subdirectories.

 

               -A, --all

                    与-u参数含义相同, but match against files  in the

                   working tree.也就意味着它能够把工作树中新增的文件, 已经被跟踪的

                   文件的修改和从工作树中删除的文件, 都提交到暂存区.

 

                    Like -u, but match against files in the working tree

                    in addition to the index. That meansthat it will find new files as

                    well as staging modified content andremoving files that are no

                    longer in the working tree.

 

                -N, --intent-to-add

                    仅仅标记给定的路径会在以后被添加, 暂存区中会为该路径提供一个入口,

                    但是不包含任何内容.当只想使用git diff查看这样文件的未跟踪的内容

                    或者使用git commit -a提交他们时,这个选项是有用的.

 

                   Record only the fact that the path willbe added later. An entry

                   for the path is placed in the indexwith no content. This is useful

                   for, among other things, showing theunstaged content of such files

                   with git diff and committing them withgit commit -a.

 

                --refresh

                    不添加文件, 只更新他们的在暂存区的stat()信息.

 

                    Don’t add the file(s), but onlyrefresh their stat() information in

                    the index.

 

                --ignore-errors

                    如果一些文件由于暂存它们时出现了错误而不能暂存, 不要停止操作,而是

                    继续暂存其他文件, 命令应该为非0值的状态返回, 可以把配置变量

                    add.ignoreErrors设置成true, 从而将忽略错误设置为默认行为.

 

                    If some files could not be addedbecause of errors indexing them,

                    do not abort the operation, butcontinue adding the others. The

                    command shall still exit with non-zerostatus. The configuration

                    variable add.ignoreErrors can be setto true to make this the

                    default behaviour.

 

                --ignore-missing

                    此选项只能和--dry-run一起使用. 通过使用此选项, 用户可以检查所给出的

                    文件是否有会被忽略掉的,不管他们是否已经在工作树中.

 

                    This option can only be used togetherwith --dry-run. By using this

                    option the user can check if any ofthe given files would be

                    ignored, no matter if they are alreadypresent in the work tree or

                    not.

 

                --

                    此选项可以用于把命令行选项和传递的文件名区分开来, (当文件名易被误认为

                    命令行选项时很有用).

 

                    This option can be used to separatecommand-line options from the

                    list of files, (useful when filenamesmight be mistaken for

                    command-line options).

 

CONFIGURATION

                可选配置变量core.excludesfile表示git-add将排除该变量所代表的文件里面

                包含的文件名模式, 与$GIT_DIR/info/exclude类似.

 

                The optional configuration variablecore.excludesfile indicates a path

                to a file containing patterns of filenames to exclude from git-add,

                similar to $GIT_DIR/info/exclude.Patterns in the exclude file are used

                in addition to those in info/exclude.See gitignore(5).

 

EXAMPLES

                把Documentation目录及其子目录下的*.txt文件添加到暂存区.

 

                Adds content from all *.txtfiles under Documentation directory and

                its subdirectories:

 

                $ git add Documentation/\*.txt

 

                注意本例中星号*在shell中被\转义了(被引起来git add Documentation/"*.txt"是

               同样的效果, 怀疑是文档有点问题.)这样一来, gitadd命令就会把Documentation/

                子目录下的*.txt文件也添加到暂存区.

 

                Note that the asterisk * is quoted from the shell in thisexample;

                this lets the command include the filesfrom subdirectories of

                Documentation/ directory.

 

                考虑把所有git-*.sh添加到暂存区的命令:

 

               Considers adding content from all git-*.sh scripts:

 

                $ git add git-*.sh

 

                因为本例允许shell展开星号(*)(i.e. 正在列出文件), 所以它不会理会

                subdir/git-foo.sh.

 

                Because this example lets the shell expand the asterisk (i.e.you

                are listing the files explicitly), it doesnot consider

                subdir/git-foo.sh.

 

INTERACTIVE MODE

                当此命令进入交互式模式的时候, 将显示status子命令的输出, 然后进入它的

                交互式命令循环.

 

                When the command enters the interactive mode, it shows theoutput of

                the status subcommand, and then goesinto its interactive command loop.

 

                命令循环显示了可用的子命令列表, 并给出提示"What now> ".大体上, 当提示以

                单个的>结尾时, 就只能挑选一个给出的选择, 然后键入回车键, 像这样:

 

                The command loop shows the list of subcommandsavailable, and gives a

                prompt "What now> ". In general,when the prompt ends with a single >,

                you can pick only one of the choicesgiven and type return, like this:

 

                    *** Commands ***

                    1: status       2: update       3: revert       4: add untracked

                    5:patch        6: diff         7: quit         8: help

                    What now> 1

                只要你键入的命令能惟一地确定一个选择, 也可以键入s 或者 sta或者status.

 

                You also could say s or sta or statusabove as long as the choice is

                unique.

 

                主命令循环有6个子命令(加上help和quit)

 

                The main command loop has 6subcommands (plus help and quit).

            status

                 显示版本库与暂存区之间的变化(i.e. 如果使用git commit, 将被提交的内容)

                 和对于每一个路径暂存区与工作目录之间的变化(i.e. git commit之前可以用

                git add进行暂存的).以下是一个样例输出:

 

                    This shows the change between HEAD andindex (i.e. what will be

                    committed if you say git commit), and betweenindex and working

                    tree files (i.e. what you could stagefurther before git commit

                    using git add) for each path. A sampleoutput looks like this:

 

                             staged     unstaged path

                    1:       binary      nothing foo.png

                    2:     +403/-35        +1/-1 git-add--interactive.perl

 

                    这表示版本库中的foo.png与暂存区中的foo.png有差别(因为是二进制文件

                    所以无法显示行号)但暂存区中和工作目录中的版本是没有差别的(如果工作目录

                    中的和暂存区中的文件有差异, binary 将显示在nothing处). 如果将暂存区中

                    的内容提交,另一个文件, git-add—interactive.perl将新增了403行, 删除

                    35行, 而且工作树中的文件有进一步的修改(新增一行, 删除一行).

                   

                    It shows that foo.png has differences from HEAD (but that isbinary

                    soline count cannot be shown) and there is no difference between

                    indexedcopy and the working tree version (if the working tree

                    version were also different, binarywould have been shown in place

                    of nothing). The other file,git-add--interactive.perl, has 403

                    lines added and 35 lines deleted ifyou commit what is in the

                    index, but working tree file hasfurther modifications (one

                    addition and one deletion).

 

            update

                     此命令显示状态信息, 以"Update>>"作为提示.当提示符以双>(>>)结尾时,

                     可以做多个选择, 用空格或者逗号来串联. 也可以使用范围表示法. E.g.

                     "2-5 7,9"将从列表中选择第2,3,4,5,7,9个提交.如果省略了范围表示法中的

                     第二个数字, 其余的提交都会被选择. E.g."7-"将从列表中选择第7,8,9三个

                    提交.也可以使用*选择所有的提交.

 

                    This shows the status information and issues an "Update>>" prompt.

                    When the prompt ends with double>>, you can make more than one

                    selection, concatenated with whitespaceor comma. Also you can say

                    ranges. E.g. "2-5 7,9" tochoose 2,3,4,5,7,9 from the list. If the

                    second number in a range is omitted,all remaining patches are

                    taken. E.g. "7-" to choose7,8,9 from the list. You can say * to

                    choose everything.

 

                    所选择的将会用*号高亮, 如下:

 

                    What you chose are then highlightedwith *, like this:

 

                               staged     unstaged path

                      1:      binary      nothing foo.png

                    * 2:    +403/-35        +1/-1 git-add--interactive.perl

 

                    想取消选择时, 可以以-作为输入的前缀, 如下:

 

                    To remove selection, prefix the inputwith - like this:

 

                    Update>> -2

 

                    做出选择后,

 

                    Aftermaking the selection, answer with an empty line to stage the

                    contents of working tree files forselected paths in the index.

 

            revert

                    它与update的UI很相像, 给定路径中被暂存的信息将被回退到版本库中的版本.

                    回退新的路径将使它们变成未跟踪的.

 

                    This has a very similar UI to update, and thestaged information

                    for selected paths are reverted tothat of the HEAD version.

                    Reverting new paths makes them untracked.

 

            add untracked

                    它与update、revert的UI很相像, 可以将未跟踪的路径添加到暂存区.

                   

                    This has a very similar UI to updateand revert, and lets you add

                    untracked paths to the index.

 

           patch

                    从给出的状态信息中选出一个路径. 选出路径后,将暂存区和工作树中的差异

                    呈现出来, 并询问你是否要将每一块修改添加到暂存区.可以选择以下的选项,

                    然后回车:

 

                    This lets you choose one path out of astatus like selection. After

                    choosing the path, it presents thediff between the index and the

                    working tree file and asks you if you want tostage the change of

                    each hunk. You can select one of thefollowing options and type

                    return:

 

                    y - 暂存此块

                    n - 不暂存此块

                    q - 退出; 不暂存此块也不暂存任何其他剩余的块

                    a - 暂存此块和文件中其他的块

                    d - 不暂存此块也不暂存文件中其他的块

                    g - 选择一个块,并到那里去

                    / - 搜索匹配给定正则表达式的块

                    j - 暂时不管此块, 查看下一个未做决定的块

                    J - 暂时不管此块, 查看下一个块

                    k -暂时不管此块, 查看上一个未做决定的块

                    K - 暂时不管此块, 查看上一个块

                    s - 把当前块拆分为较小的块

                    e - 手动编辑当前块

                    ? -打印帮助

 

                    y - stage this hunk

                    n - do not stage this hunk

                    q - quit; do not stage this hunk nor anyof the remaining ones

                    a - stage this hunk and all later hunks inthe file

                    d - do not stage this hunk nor any of thelater hunks in the file

                    g - select a hunk to go to

                    / - search for a hunk matching the givenregex

                    j - leave this hunk undecided, see nextundecided hunk

                    J - leave this hunk undecided, see nexthunk

                    k -leave this hunk undecided, see previous undecided hunk

                    K - leave this hunk undecided, seeprevious hunk

                    s - split the current hunk into smallerhunks

                    e - manually edit the current hunk

                    ? -print help

 

                    当处理完所有的块之后, 如果有任何一块被选择上,那么暂存区将会以选择的块

                    进行更新. 如果将配置变量interactive.singlekey设为true, 那么在这里也可以

                    省略回车.

                   

                    After deciding the fate for all hunks,if there is any hunk that

                    was chosen, the index is updated withthe selected hunks.

 

                    You can omit having to type returnhere, by setting the

                    configuration variableinteractive.singlekey to true.

 

            diff

                    可以回顾哪些东西将被提交.(i.e. 在版本库与暂存区之间)

 

                    This lets you review what will becommitted (i.e. between HEAD and

                    index).

 

EDITING PATCHES

                通过git add -e调用或者在交互式块选择器选择e选项将在文本编辑器里打开补丁;

                当编辑器退出时, 结果将提交到暂存区. 可以随意的修改补丁, 但是一些修改将导致

                令人困惑的结果, 甚至无法提交这个补丁. 如果想完全退出此操作(i.e. 不暂存任何

                东西), 简单地将补丁中所有行都删掉. 下面的列表描述了在补丁文件中一些常见的

                问题, 编辑操作对它们会有意义.

 

                Invoking git add -e or selecting efrom the interactive hunk selector

                will open a patch in your editor;after the editor exits, the result is

                applied to the index. You are free tomake arbitrary changes to the

                patch, but note that some changes mayhave confusing results, or even

                result in a patch that cannot beapplied. If you want to abort the

                operation entirely (i.e., stage nothing new in the index),simply

                delete all lines of the patch. The listbelow describes some common

                things you may see in a patch, andwhich editing operations make sense

                on them.

 

            added content

                 已经添加的内容以"+"开始.通过删除它们可以防止被暂存.

 

                  Added content is represented by linesbeginning with "+". You can

                  prevent staging any addition lines bydeleting them.

 

            removed content

                  被删除的内容以"-"开头.可以把"-"换成" "(空格), 这样就不会删除它们了.

 

                  Removed content is represented bylines beginning with "-". You can

                  preventstaging their removal by converting the "-" to a " "

                  (space).

            modified content

                  修改的内容通过"-"(删除旧的内容)后跟着"+"(替换的内容).可以把"-"换成""

                  (空格), 并把"+"行删掉, 防止修改加入到暂存区. 谨防只修改"-"行或者只修改

                  "+"行, 将会把令人困惑的修改提交到暂存区.

 

                  Modified content is represented by"-" lines (removing the old

                  content) followed by "+"lines (adding the replacement content).

                  You can prevent staging themodification by converting "-" lines to

                  " ", and removing"+" lines. Beware that modifying only half of the

                  pair is likely to introduce confusingchanges to the index.

 

                  还有一些更加复杂的操作, 因为这些补丁只会提交到暂存区而不是工作树中,

                  工作树中的内容看起来是吧暂存区中的内容撤销掉了. 例如, 如果向暂存区

                  加入了一行但既不是在HEAD上也不是在工作树中,will stage the new line

                  for commit, 但是在工作树中新增的行就好像是被还原了.

                  应该避免使用这些功能, 或者要超级小心地使用.

 

                    There are also more complexoperations that can be performed. But

                    beware that because the patch isapplied only to the index and not the

                    working tree, the working treewill appear to "undo" the change in the

                    index. For example, introducing anew line into the index that is in

                    neither the HEAD nor the workingtree will stage the new line for

                    commit, but the line will appearto be reverted in the working tree.

 

                    Avoid using these constructs, ordo so with extreme caution.

 

            removing untouched content

                    暂存区与工作树中相同的内容也有可能显示为上下文行, 以" " (空格)

                    开头,通过把空格换成一个"-"从而把上下文行删除,并暂存起来. 工作

                    树中显示好像有把这个内容重新添加了一样.

 

                    Content which does not differ betweenthe index and working tree

                    may be shown on context lines,beginning with a " " (space). You

                    can stage context lines for removal byconverting the space to a

                    "-". The resulting workingtree file will appear to re-add the

                    content.

 

            modifying existing content

                    可以修改上下文行并提交暂存(通过把"" 换成 "-"), 在新增内容前增加

                    "+". 类似的, one can modify"+" lines for existing additions or

                    modifications.所有情况下, 新的修改在工作树中都会表现为被还原了.

 

                    One can also modify context lines bystaging them for removal (by

                    converting " " to"-") and adding a "+" line with the new content.

                    Similarly, one can modify"+" lines for existing additions or

                    modifications. In all cases, the newmodification will appear

                    reverted in the working tree.

 

             new content

                    也可以增加补丁中不存在的内容; 只是简单地增加以"+"开头的行. 在

                    工作树中, 新的增加好像是被还原了.

 

                    You may also add new content that doesnot exist in the patch;

                    simply add new lines, each startingwith "+". The addition will

                    appear reverted in the working tree.

 

                    这里也有一些应该被完全避免的操作, 因为这将导致补丁无法被提交:

                    · 添加上下文或者删除"-"

                    · 删除上下文或者删除删除的行

                    · 修改内容的上下文或者修改被删除的行

 

                    There are also several operationswhich should be avoided entirely, as

                    they will make the patchimpossible to apply:

 

                    ·  adding context (" ") or removal ("-") lines

 

                    ·  deleting context or removal lines

 

                    ·  modifying the contents of context or removal lines

 

SEE ALSO

                git-status(1) git-rm(1) git-reset(1)git-mv(1) git-commit(1) git-

                update-index(1)


你可能感兴趣的:(GIT帮助手册)