Git基本操作

git init

  Git 使用 git init 命令来初始化一个 Git 仓库,Git 的很多命令都需要在 Git 的仓库中运行,所以 git init 是使用 Git 的第一个命令。
  在执行完成 git init 命令后,Git 仓库会生成一个 .git 目录,该目录包含了资源的所有元数据,其他的项目目录保持不变。

  • 使用当前目录作为 Git 仓库:git init,该命令执行完后会在当前目录生成一个 .git 目录
  • 使用指定的目录作为 Git 仓库:git init newrepo,初始化后,会在 newrepo 目录下出现一个名为 .git 的目录。
$ mkdir test
$ cd test/
$ git init
Initialized empty Git repository in D:/Workspace/Git/test/.git/

git status

  git status 命令用于查看项目的当前状态。工作区和仓库在被操作的过程中,状态会不断发生变化。在 Git 操作过程中时常用 git status 命令查看当前状态。
  在使用该命令时加 -s 参数,可以获得简短的结果输出。如果没有加该参数则会详细输出内容。

$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

git add

  如果只是用 Git 仓库的工作区创建了文件,那么该文件并不会被记入 Git 仓库的版本管理对象当中。要想让文件成为 Git 仓库的管理对象,就需要使用 git add 命令将其加入暂存区(Stage 或者 Index)中。暂存区就是提交之前的一个临时区域。

$ touch README.md

$ git status
On branch master

No commits yet

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

        README.md

nothing added to commit but untracked files present (use "git add" to track)

  可以看到在 Untracked files 中显示了 README.md 文件。类似地,只要对 Git 的工作区或仓库进行操作,git status 命令的显示结果就会发生变化。

$ git add README.md

$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   README.md

git commit

  使用 git add 命令将想要快照的内容吸入缓存区,而执行 git commit 将缓存区文件实际保存到仓库的历史纪录中。通过这些记录,我们就可以在工作区中复原文件。
  在 git commit 中使用 -m 选项以在命令行中提交注释。如果没有设置 -m 选项,Git 会尝试为你打开一个编辑器以填写提交信息。

$ git commit -m 'First commit'
[master (root-commit) 35c5cc1] First commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md

git log

  git log 命令可以查看以往仓库中提交的日志。

$ git log
commit 35c5cc191fc18606a23371333058d01eed4db101 (HEAD -> master)
Author: lucky-zhangcd <************@qq.com>
Date:   Mon Jun 18 20:07:
  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值