commit913bc886088dabee0af5b06351450cad60102c23 (HEAD -> master) Author: fightinggg <246553278@qq.com> Date: Sun Mar 2916:45:192020 +0800
first commit
我们尝试将b.txt也提交上去
1 2
git add b.txt git commit -m 'second commit'
再次查看log
1 2 3 4 5 6 7 8 9 10 11
commit fbdd818849343a78d0e6ccd8d5ce0f35d9d8b123 (HEAD -> master) Author: fightinggg <246553278@qq.com> Date: Sun Mar 2916:48:562020 +0800
second commit
commit913bc886088dabee0af5b06351450cad60102c23 Author: fightinggg <246553278@qq.com> Date: Sun Mar 2916:45:192020 +0800
first commit
更多的文件
加入更多的文件
1
touch a2.txt a3.txt a4.txt a5.txt
将他们全部提交
1 2 3
git add . git commit -m 'third commit' git log
我们现在看到有了3次提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
commit9d1f0b1c3ecd11e5c629c0dd0bfdf4118ad4e999 (HEAD -> master) Author: fightinggg <246553278@qq.com> Date: Sun Mar 2916:52:362020 +0800
third commit
commit fbdd818849343a78d0e6ccd8d5ce0f35d9d8b123 Author: fightinggg <246553278@qq.com> Date: Sun Mar 2916:48:562020 +0800
second commit
commit913bc886088dabee0af5b06351450cad60102c23 Author: fightinggg <246553278@qq.com> Date: Sun Mar 2916:45:192020 +0800
first commit
修改后的文件
如果我们修改了一个文件
1
echo "hellp" >> a.txtgit status
我们看到了git提示有文件被修改了
1
On branch masterChanges not staged forcommit: (use "git add <file>..." toupdate what will be committed) (use "git checkout -- <file>..." todiscard changes in working directory) modified: a.txtno changes added tocommit (use "git add" and/or "git commit -a")
将它提交
1
git commit -am 'modified a.txt'
看到了输出
1
commit2e625b6f5de426675e4d2edf8ce86a75acc360de (HEAD -> master)Author: fightinggg <246553278@qq.com>Date: Sun Mar 2916:57:432020 +0800 modified a.txtcommit 9d1f0b1c3ecd11e5c629c0dd0bfdf4118ad4e999Author: fightinggg <246553278@qq.com>Date: Sun Mar 2916:52:362020 +0800 third commitcommit fbdd818849343a78d0e6ccd8d5ce0f35d9d8b123Author: fightinggg <246553278@qq.com>Date: Sun Mar 2916:48:562020 +0800 second commitcommit 913bc886088dabee0af5b06351450cad60102c23Author: fightinggg <246553278@qq.com>Date: Sun Mar 2916:45:192020 +0800 first commit
追加提交
如果我们发现上一次的提交是没有用的,或者说不想让它出现,又或者说想把它删了,我们使用如下指令
1
echo "b" >> b.txtgit commit --amend
我们发现我们进入到了vim中
1
modified a.txt# Please enter the commit message for your changes. Lines starting# with'#' will be ignored, and an empty message aborts the commit.## Date: Sun Mar 2916:57:432020 +0800## On branch master# Changes to be committed:# modified: a.txt## Changes not staged for commit:# modified: b.txt#
我们将它修改为
1
modified a.txt b.txt# Please enter the commit message for your changes. Lines starting# with'#' will be ignored, and an empty message aborts the commit.## Date: Sun Mar 2916:57:432020 +0800## On branch master# Changes to be committed:# modified: a.txt## Changes not staged for commit:# modified: b.txt#
最后再次查看log
1
git log--oneline
我们得到了下面的输出,上一次的提交被现在的提交覆盖了
1
105a02a (HEAD -> master) modified a.txt b.txt9d1f0b1 third commitfbdd818 second commit913bc88 first commit
撤销
假设你犯了一个严重的错误
1
rm*.txt
代码没了我们来看看git的状态
1
git status
看到了如下的输出
1
On branch masterChanges not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) deleted: a.txt deleted: a2.txt deleted: a3.txt deleted: a4.txt deleted: a5.txt deleted: b.txtno changes added to commit (use "git add"and/or "git commit -a")
On branch masterChanges to be committed: (use "git reset HEAD <file>..." to unstage) modified: a.txtChanges not staged forcommit: (use "git add <file>..." toupdate what will be committed) (use "git checkout -- <file>..." todiscard changes in working directory) modified: a.txt