git常用命令

本文示例前提:

1、你已经安装了git ,2、你对git基本概念有一定了解。

首先git是版本控制器,是linux作者linus写的(他感觉svn很low吧)

下面本人参考资料综合介绍下git常用命令

mkdir <name> 创建版本库,也可以自己创建个文件夹 右键git Bash here,没有右键此选项的话 你安装有问题


创建个 test-git作为版本库,

pwd 显示当前目录

$ pwd
/f/git/test-git

cd <path>进入下级目录

cd .. 返回上级目录

git init 当前目录创建新的git仓库,当前目录下会多个.git目录

$ git init
Initialized empty Git repository in F:/git/test-git/.git/    #翻译下是:在这个目录下初始化空Git存储库 很友好

在test-git文件夹下新建demo.txt

录入内容 git是版本控制器

git status命令 查看文件状态

$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        demo.txt

nothing added to commit but untracked files present (use "git add" to track)
意思是这个文件还没添加 

git add file 将文件添加到缓存

git add demo.txt

git commit 将文件提交到仓库 例如 git commit -m “添加了demo.txt文件"    -m 后面为本次提交说明 用英文双引

$ git commit -m "添加了demo.txt文件"
[master (root-commit) 3c8b2de] 添加了demo.txt文件
 1 file changed, 1 insertion(+)
 create mode 100644 demo.txt

git add 可以多次add不同文件 例如 

git add a.txt
git add b.txt  c.txt

然后 git commit -m "加了三个文件"

修改 demo.txt 内容

git是版本控制器
git很好用

然后利用 git status 查看更改状态

$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   demo.txt

no changes added to commit (use "git add" and/or "git commit -a")
意思是 demo.txt被修改过,但未提交

发现有修改地方,但是想看到具体修改内容 则使用 git diff 

$ git diff
diff --git a/demo.txt b/demo.txt
index 621f538..f44e5c8 100644
--- a/demo.txt
+++ b/demo.txt
@@ -1 +1,2 @@
-git<CA>ǰ汾<BF><D8><D6><C6><C6><F7>
\ No newline at end of file
+git<CA>ǰ汾<BF><D8><D6><C6><C6><F7>
+git<BA>ܺ<C3><D3><C3>
\ No newline at end of file

没出现这种情况最好,出现的话,不好意思,乱码了,为何乱码,因为windows文本编辑器的问题,建议你使用notepad++进行编译

下载地址:https://notepad-plus-plus.org/

设置下编码:

author就不展示了
commit 后面为commit id 版本号
下面可以用 git reset 返回到上一个或者N个版本,上篇文章记录了master用HEAD指针指向了当前的版本,上个版本则是HEAD^ 上N个版本则是 HEAD~N表示
回到上一个版本 

继续 git diff

$ git diff
diff --git a/demo.txt b/demo.txt
index 621f538..9b5f64a 100644
--- a/demo.txt
+++ b/demo.txt
@@ -1 +1,2 @@
-git<CA>ǰ汾<BF><D8><D6><C6><C6><F7>
\ No newline at end of file
+git是版本控制器
+git很好用
\ No newline at end of file
已经展示出了修改后内容,上面的乱码可以忽略掉,因为之前我提交时候未设置编码

$ git add demo.txt
$ git commit -m "修改了内容"
[master 1ad0316] 修改了内容
 1 file changed, 1 insertion(+), 1 deletion(-)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值