设置本地信息:设置本地用户名和本地邮箱:
$ git config --global user.name "uppered"
$ git config --global user.email "1150725719@qq.com"
检查当前的配置信息:
$ git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=D:/Git/mingw64/etc/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=true
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
新建初始化一个项目:
git init
指定文件夹为一个仓库:
git init test
将文件纳入版本控制:
git add test.txt
将文件提交到本地仓库:
$ git commit -m "测试" test.txt test.txt
[master a82d1e6] 测试
1 file changed, 1 insertion(+)
create mode 100644 test.txt
将已有仓库克隆到本地:
$ git clone git://github.com/test/test.git
将已有仓库克隆到本地自定义目录:
$ git clone git://github.com/test/test.git test1
查看上次提交后是否有改动:
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
加-s参数简短输出:
$ git status -s
M test.txt
查看具体修改的不同:
- 尚未缓存的改动:git diff
- 查看已缓存的改动: git diff --cached
- 查看已缓存的与未缓存的所有改动:git diff HEAD
- 显示摘要而非整个 diff:git diff --stat
$ git diff
diff --git a/test.txt b/test.txt
index ad6ea93..cd3638d 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1 @@
-打撒的撒的实打实啊啊啊啊打撒
\ No newline at end of file
+打撒的撒的实打实啊啊啊啊打撒1111
\ No newline at end of file
将文件提交到远程仓库:
$ git push
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 502 bytes | 502.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/dengziliang/el_boot.git
be29b45..a599815 master -> master
取消缓存已缓存的内容:
$ git status -s
M 1111.txt
M 2222.txt
huawei@DENGZL MINGW64 ~/Desktop/新建文件夹/el_boot (master)
$ git reset HEAD 1111.txt
Unstaged changes after reset:
M 1111.txt
M 2222.txt
huawei@DENGZL MINGW64 ~/Desktop/新建文件夹/el_boot (master)
$ git status -s
M 1111.txt
M 2222.txt
将文件从缓存区中移除:
huawei@DENGZL MINGW64 ~/Desktop/新建文件夹/el_boot (master)
$ ls
2222.txt test.txt
huawei@DENGZL MINGW64 ~/Desktop/新建文件夹/el_boot (master)
$ git rm 2222.txt
rm '2222.txt'
huawei@DENGZL MINGW64 ~/Desktop/新建文件夹/el_boot (master)
$ ls
test.txt
在工作区保留该文件:
$ git rm --cached test.txt
rm 'test.txt'
huawei@DENGZL MINGW64 ~/Desktop/新建文件夹/el_boot (master)
$ ls
test.txt
从远程地址更新文件:
$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 1.02 KiB | 30.00 KiB/s, done.
From https://gitee.com/dengziliang/el_boot
6bc9ac4..dcc1af1 master -> origin/master
error: Your local changes to the following files would be overwritten by merge:
1111.txt
test.txt
Please commit your changes or stash them before you merge.
Aborting
Updating 63e1a46..dcc1af1