今天晚上学习了 git add/ git reset HEAD <file>/git status/git diff等命令,接下来要说git的很重要命令了: git commit/git pull/git push/git fetch/git merge
发现git diff还有一个功能没有写出实例,就是 git diff HEAD 查看已缓存的未缓存的所有改动。
(base) ligangdeMacBook-Pro:gitFolder lg$ git diff HEAD
diff --git a/123.png b/123.png
new file mode 100644
index 0000000..e220f35
Binary files /dev/null and b/123.png differ
diff --git a/testData.rtf b/testData.rtf
new file mode 100644
index 0000000..426da6a
--- /dev/null
+++ b/testData.rtf
@@ -0,0 +1,632 @@
+{\rtf1\ansi\ansicpg936\cocoartf1561\cocoasubrtf400
+{\fonttbl\f0\fnil\fcharset134 PingFangSC-Regular;\f1\fswiss\fcharset0 Helvetica;\f2\fnil\fcharset0 HelveticaNeue;
+\f3\fswiss\fcharset0 ArialMT;\f4\froman\fcharset0 Times-Roman;\f5\fnil\fcharset0 Menlo-Regular;
+}
+{\colortbl;\red255\green255\blue255;\red36\green37\blue38;\red0\green0\blue0;\red234\green248\blue235;
+\red19\green118\blue70;\red255\green255\blue254;\red0\green0\blue0;\red63\green63\blue63;\red255\green255\blue255;
+\red114\green120\blue138;\red50\green55\blue75;\red18\green31\blue60;\red181\green0\blue19;\red242\green243\blue255;
+}
感觉这个功能用的也不是很多
git commit 使用git add命令将要快照的内容写入缓存区,而执行git commit将缓存区内容填入到仓库中。git 会为每一次提交记录提交人的名字和邮箱地址,需要先配置用户名和邮箱地址。
$ git config --global user.name 'xxxxx'
$ git config --global user.email xxxxx@163.com
然后我们就准备要提交内容到远程仓库了
git commit -m '第一次版本提交'
(base) ligangdeMacBook-Pro:gitFolder lg$ git commit -m '第一次提交'
[master bc86ba5] 第一次提交
2 files changed, 631 insertions(+)
create mode 100644 123.png
create mode 100644 testData.rtf
已经执行完了快照,再使用git status查看下状态
(base) ligangdeMacBook-Pro:gitFolder lg$ git commit -m '第二次提交'
[master 78a940a] 第二次提交
1 file changed, 3 insertions(+), 2 deletions(-)
(base) ligangdeMacBook-Pro:gitFolder lg$ git status
On branch master
nothing to commit, working tree clean
可以看到,使用 git add将文件写入到缓存区,然后使用git commit提交之后,再查看 git status,就会提示没有需要提交的文件了
然后我们对文件进行删减,查看下摘要
(base) ligangdeMacBook-Pro:gitFolder lg$ git diff --stat
testData.rtf | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
可以看出我们对 testData.rtf文件进行了修改,然后我们提交这些修改
如果我们在 -m后没有添加内容,会提示需要在 -m 后添加 value
(base) ligangdeMacBook-Pro:gitFolder lg$ git commit -m
error: switch `m' requires a value
usage: git commit [<options>] [--] <pathspec>...
-q, --quiet suppress summary after successful commit
-v, --verbose show diff in commit message template
Commit message options
-F, --file <file> read message from file
--author <author> override author for commit
--date <date> override date for commit
-m, --message <message>
commit message
-c, --reedit-message <commit>
reuse and edit message from specified commit
-C, --reuse-message <commit>
reuse message from specified commit
--fixup <commit> use autosquash formatted message to fixup specified commit
--squash <commit> use autosquash formatted message to squash specified commit
--reset-author the commit is authored by me now (used with -C/-c/--amend)
-s, --signoff add Signed-off-by:
-t, --template <file>
use specified template file
-e, --edit force edit of commit
--cleanup <default> how to strip spaces and #comments from message
--status include status in commit message template
-S, --gpg-sign[=<key-id>]
GPG sign commit
Commit contents options
-a, --all commit all changed files
-i, --include add specified files to index for commit
--interactive interactively add files
-p, --patch interactively add changes
-o, --only commit only specified files
-n, --no-verify bypass pre-commit and commit-msg hooks
--dry-run show what would be committed
--short show status concisely
--branch show branch information
--ahead-behind compute full ahead/behind values
--porcelain machine-readable output
--long show status in long format (default)
-z, --null terminate entries with NUL
--amend amend previous commit
--no-post-rewrite bypass post-rewrite hook
-u, --untracked-files[=<mode>]
show untracked files, optional modes: all, normal, no. (Default: all)
如果觉得 git add添加文件到缓存区的流程太过复杂,可以使用 git commit -a来跳过。我们刚才已经修改了文件但是还没有上传,来试试这个命令
(base) ligangdeMacBook-Pro:gitFolder lg$ git commit -am '第三次提交'
[master 593b107] 第三次提交
1 file changed, 1 insertion(+), 10 deletions(-)
其中 -a m 不能分开,必须要连在一起写,要不会报错
好的,今天先到这里吧~