Git 初接触 (二) 在项目中简单使用Git

下面我们就尝试在项目中简单的使用一下Git

  • 建立项目

    在这里为了测试我建立了一个 非常简单的文件夹program 当作我们的项目目录 里面的文件非常的简单 就 index.phpindex.html 两个文件

    这里写图片描述

    文件的内容如下

 index.php
 ----------------
 <?php

 echo "this is a program";

 ****************************  分割线

 index.html
 ----------------
 <!DOCTYPE html>
 <html>
 <head>
     <title>Git</title>
 </head>
 <body>
 <h1>Git test</h1>
 </body>
 </html>
  • 初始化 Git

    我们进入 项目目录 右键使用 Git Bash 输入 git init 命令即可 初始化 Git 并生成 .git 目录

    这里写图片描述

    这里写图片描述


  • Git 的区域

    在Git 中 总共有三个区域 它们分别是 我们初始进入就位于工作区

  工作区(working tree)
  暂存区(stage)
  版本库(repository)


  • Git 文件的状态

    Untracked: 未跟踪 此文件在文件夹中 但并没有加入到git库 不参与版本控制 通过git add 状态变为Staged

    Unmodify: 文件已经入库 未修改 即版本库中的文件快照内容与文件夹中完全一致 这种类型的文件有两种去处 如果它被修改 而变为Modified 如果使用git rm移出版本库 则成为Untracked文件

    Modified: 文件已修改 仅仅是修改 并没有进行其他的操作 这个文件也有两个去处 通过git add可进入暂存staged状态 使用git checkout 则丢弃修改过 返回到unmodify状态 这个git checkout即从库中取出文件 覆盖当前修改

    Staged: 暂存状态 执行git commit则将修改同步到库中 这时库中的文件和本地文件又变为一致 文件为Unmodify状态 执行git reset HEAD filename取消暂存 文件状态为Modified


  • 将文件添加到版本库

    先使用 git status 检查一下我们Git的状态

On branch master

Initial commit

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

        index.html
        index.php

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

发现 index.phpindex.html 都未被追踪 所以我们先使用 git add 命令 追踪一下 首先追踪 index.php

执行命令 git add index.php 我们发现

On branch master

Initial commit

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

        new file:   index.php

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

        index.html

index.php 正在暂存区里等待被提交 而 index.html 还处于未追踪状态

我们尝试提交一下 index.php 使用命令 git commit 提交 使用参数 -m 可以为提交增加备注

$ git commit -m 'first add'

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <my@licheng▒▒.(none)>) not allowed

提交后我们发现 我们没有 设置我们的用户名和邮箱 现在我们来设置一下 如提示 使用 git config --global user.email "you@example.com"git config --global user.name "Your Name"

设置完后 可以使用 git config --list 查看 如下

$ git config --list
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=C:/Program Files (x86)/Git/mingw32/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true
user.email=1150400220@qq.com
user.name=lychee
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly

下面 我们重新提交 git commit -m 'first add'

$ git commit -m 'first add'
[master (root-commit) dcfb0a8] first add
 1 file changed, 3 insertions(+)
 create mode 100644 index.php

git status 检查一下Git的状态

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

        index.html

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

只有 index.html 未被追踪了

使用 git log 命令查看当前分支的提交历史


$ git log
commit dcfb0a859c548128ff836ca94c6c9531ee7ff9c5
Author: lychee <1150400220@qq.com>
Date:   Mon Dec 18 23:13:13 2017 +0800

    first add

到现在 我们已经将 index.php 提交到我们的版本库里面去了

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值