当前位置:   article > 正文

git指令练习_怎么练习git 命令

怎么练习git 命令

附git菜鸟教程:
https://www.runoob.com/git/git-basic-operations.html
创建一个目录gitdemo

cd
mkdir gitdemo
cd gitdemo/
ll
  • 1
  • 2
  • 3
  • 4

在这里插入图片描述

git init 命用于在目录中创建新的 Git 仓库。

在目录中执行 git init 就可以创建一个 Git 仓库了。

 /usr/local/git-2.6.2/bin/git init
  • 1

在这里插入图片描述

ll -a
ll .git/
ll
  • 1
  • 2
  • 3

在这里插入图片描述

创建test.txt文本文件

vi test.txt
  • 1

第一次编辑

this is first line
  • 1

ESC

:wq
  • 1

在这里插入图片描述
git status 命令用于查看在你上次提交之后是否有对文件进行再次修改。

git status
  • 1

在这里插入图片描述
添加当前目录所有文件到仓库并查看在你上次提交之后是否有对文件进行再次修改

git add ./
git status
  • 1
  • 2

在这里插入图片描述
提交暂存区的指定文件到仓库区

git commit -m "first commit"
  • 1

在这里插入图片描述
我们需要先设置提交的用户信息,包括用户名和邮箱:

git config user.name "zhangsan"
git config user.email "zhangsan@162.com"
  • 1
  • 2
git commit -m "first commit"
  • 1

在这里插入图片描述
在这里插入图片描述
编辑test.txt文件

ll
vi test.txt
  • 1
  • 2

新增一行

second line
  • 1

在这里插入图片描述
ESC
退出

:wq
  • 1
git status
  • 1

在这里插入图片描述

git commit -a -m "second commit"
  • 1

在这里插入图片描述

–oneline 标记的作用是把每一个提交信息压缩为一行。默认情况下只会展示提交 ID与提交信息的首行。

git log --oneline
ll
  • 1
  • 2

在这里插入图片描述
在这里插入图片描述

第三次编辑

vi test.txt
  • 1

在这里插入图片描述
第三次提交

git commit -a -m "third commit"
git log --oneline
  • 1
  • 2

在这里插入图片描述
查看历史提交记录

git log
  • 1

在这里插入图片描述
使用reset回退版本

$ git reset HEAD^            # 回退所有内容到上一个版本  
$ git reset HEAD^ hello.php  # 回退 hello.php 文件的版本到上一个版本  
$ git  reset  052e           # 回退到指定版本
  • 1
  • 2
  • 3
git reset HEAD^
  • 1

在这里插入图片描述

git log --oneline
ll
  • 1
  • 2

在这里插入图片描述

more test.txt
  • 1

在这里插入图片描述
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/493695
推荐阅读
相关标签
  

闽ICP备14008679号