GIt常用命令

设置本地信息:设置本地用户名和本地邮箱:

$ 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

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

uppered

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值