git初阶笔记

git的学习笔记1

linux内核开源项目有着为数众多的参与者,绝大多数linux内核维护工作都花在提交补丁和保存归档的繁琐事务

​ 创建git的目标:

  • ​ 速度

  • 简单的设计

  • 对非线性开发模式的强力支持(允许成千上万并开发的分支)

  • 完全分布式

  • 有能力高效管理类似linux内核一样的超大规模项目

    自诞生2005年以来,git在高度易用的同时,任然保留初期的目标

git的三种状态

​ 已提交(committed):修改文件,但为保存数据库中

​ 已修改(modified):对一个已修改文件的当前版本做了标记,使之包含在下次提交的快照中

​ 已暂存(staged):数据已经安全地保存在本地数据库中

git的三个阶段

​ 工作区:对项目的某个版本独立提取出来的内容。

​ 暂存区:保存下次将要提交的文件列表信息

​ Git目录:Fit来保存项目的元数据和对象数据库的地方

工作流程:

​ 在工作区中修改文件

​ 将你想要下次提交的更改选择地暂存,这样只会将更改的部分添加到暂存区

​ 提交更新,找到暂存区的文件,将快照永久性存储到Git目录

命令行

​ git自带一个git config的工具来帮助设置控制Git外观和行为的配置变量。

​ git config --list --show-origin(查看所有的配置以及他们所在的文件)

  • ​ 用户信息

    安装git之后,第一件事就是设置你的用户名和邮箱地址 因为每个git提交都会使用这些信息;写入每一次提交是不可更改

    • git config --global user.name “tonglian”
    • git config --global user.email [email protected]
  • 文本编辑器

    • 修改默认的文本编辑器:
    • git config --global core.editor emacs
  • 检查配置信息

    • 如果想要检查你的配置,可以使用git config --list命令列出所有git当时能找的配置
      git初阶笔记_第1张图片
  • 获取帮助:在git获取帮助

    • git help

    • git --help

    • man git-

$ git help
usage: git [–version] [–help] [-C ] [-c =]
[–exec-path[= ]] [–html-path] [–man-path] [–info-path]
[-p | --paginate | -P | --no-pager] [–no-replace-objects] [–bare]
[–git-dir= ] [–work-tree= ] [–namespace=]
[]

These are common Git commands used in various situations:

various situations:各种情况 common :常见的

start a working area (see also: git help tutorial)

启动工作区

clone Clone a repository into a new directory
init Create an empty Git repository(存储库) or reinitialize(重新初始化) an existing one

work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
restore Restore(还原) working tree files
rm Remove files from the working tree and from the index
sparse-checkout Initialize and modify the sparse-checkout

examine(检查) the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
diff Show changes between commits, commit and working tree, etc
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status

grow, mark and tweak(调整) your common history
branch List, create, or delete branches
commit Record changes to the repository
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
reset Reset current HEAD to the specified state
switch Switch branches
tag Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects

‘git help -a’ and ‘git help -g’ list available subcommands and some
concept guides. See 'git help ’ or 'git help ’
to read about a specific subcommand or concept.
See ‘git help git’ for an overview of the system.

Git基础

获取Git仓库:

  • ​ 将尚未进行版本控制的本地目录转换为Git仓库

  • ​ 从其他服务器克隆一个工作Git仓库

    创建一个git仓库

    ​ 1.先进入项目目录

    ​ 2.在用git init

    该命令将创建一个名为.git的子目录,这个子目录含有初始化的Git仓库中所有的必须文件,这些文件是Git仓库的骨干,但是这个时候,我们仅仅是做了一个初始化的操作,你的项目里的文件还没有被跟踪。

克隆现有的仓库:

​ git克隆是该仓库服务器上的所有数据(clone)其他的vsc使用checkout

eg:** git clone https://gitee.com/Montaro2017/html-pratice.git**

记录每次更新的记录

  1. ​ 每个文件都不外乎两种状态:以跟踪或未跟踪;
  2. 已跟踪:那些被纳入了版本控制的文件,在上次快照中有他们的记录也就是Git已经知道的文件
  3. git status :查看哪些文件处于什么状态。
  4. 在克隆之后我们创建一个新的a.txt文件。如果之前不存在这个文件,使用git status命令则会出现

git初阶笔记_第2张图片

出现红色代表的是两个文件没有被git跟踪

跟踪新的文件

​ 对a.txt进行跟踪

​ git add a.txt

git初阶笔记_第3张图片

changes to be committed 说明以文件是以暂存状态;

你可能感兴趣的:(git)