git add -u与-A .三者的区别 以及 git commit --amend 改写提交

https://blog.csdn.net/ly890700/article/details/53526744

https://blog.csdn.net/garfielder007/article/details/60885000

 

git add -u:将文件的修改、文件的删除,添加到暂存区。

git add .:将文件的修改,文件的新建,添加到暂存区。

git add -A:将文件的修改,文件的删除,文件的新建,添加到暂存区。

 

-u就是update的意思,只会标记本地有改动(包括删除和修改)的已经追踪的文件

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


           If no 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

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


           If no 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.  git add -A   保存所有的修改

2.  git add .     保存新的添加和修改,但是不包括删除

3.  git add -u   保存修改和删除,但是不包括新建文件。

如图:

 

 

commit --amend

为了节省时间,这个教程使用现有的历史记录作为本地数据库。

从这里下载

我们将修改最近一次的提交。

首先进入stepup-tutorial/tutorial1目录。本地端的历史记录状态如下图显示。

用log命令确认历史记录。

$ git log
commit 326fc9f70d022afdd31b0072dbbae003783d77ed
Author: yourname 
Date:   Mon Jul 16 23:17:56 2012 +0900

    添加add的说明

commit 48eec1ddf73a7fb508ef664efd6b3d873631742f
Author: yourname 
Date:   Mon Jul 16 23:16:14 2012 +0900

    first commit

首先打开sample.txt档案,并添加commit的注释。

连猴子都懂的Git命令
add 把变更录入到索引中
commit 记录索引的状态

添加 --amend 选项,然后提交。

$ git add sample.txt
$ git commit --amend

编辑工具会显示最近一次提交的提交消息,把消息修改为「添加add和commit的讲解」并进行保存。

现在已经修改了提交的内容,然后用log命令确认历史记录和提交消息。

commit --amend

$ git log
commit e9d75a02e62814541ee0410d9c1d1bf47ab1c057
Author: yourname 
Date:   Mon Jul 16 23:17:56 2012 +0900

    添加add和commit的讲解

commit 48eec1ddf73a7fb508ef664efd6b3d873631742f
Author: yourname 
Date:   Mon Jul 16 23:16:14 2012 +0900

    first commit
from: http://backlogtool.com/git-guide/cn/stepup/stepup7_1.html

你可能感兴趣的:(杂七杂八)