嵌入式Linux(五):git 使用笔记

前言

Git基本上是一个程序员必备的技能,这里就一下各种情况的使用记录。
progo中文版在线文档

git help
:::::::::::::::
These are common Git commands used in various situations:

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
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
   bisect     Use binary search to find the commit that introduced a bug
   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
   checkout   Switch branches or restore working tree files
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   merge      Join two or more development histories together
   rebase     Reapply commits on top of another base tip
   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 <command>' or 'git help <concept>'

(一)开启一个git项目

获取帮助信息

$ git help <verb>
$ git <verb> --help
$ man git-<verb>

git config

第一次运行需要配置user email

//配置用户名 邮箱
git config --global user.name "夜梦"
git config --global user.email johndoe@example.com

//查看配置信息
git config -l

git init

开启一个git 项目

git clone

克隆一个git仓库

//获取一个远程仓库
git clone <url>
//获取远程仓库,并重命名那个本地的项目名
git clone https://github.com/libgit2/libgit2 mylibgit

(二) 添加删除

Git 项目拥有三个阶段:工作区、暂存区以及 Git 目录
基本的 Git 工作流程如下:
在工作区中修改文件。
将你想要下次提交的更改选择性地暂存,这样只会将更改的部分添加到暂存区。
提交更新,找到暂存区的文件,将快照永久性存储到 Git 目录。

git status

查看当前所有文件状态

//完整版
git status
//紧凑版
git status -s

git add

工作区的文件提交到缓存区

//添加指定文件
git add code.c
//添加格式为.c的文件
git add *.c
//添加所有文件
git add .

git commit

缓存取的文件添加到git目录

git commit -m "message of description of this commit!"

git diff

查看当前修改与上一版本的差异

git diff

(三) 版本回退向前

git log

查看当面到以前的所有log

//完整版
git log
//展示log为但一行
git log --pretty=oneline

git reflog

查看所有的log

git reflog

git reset

切换指定版本(log)
或撤销操作

//回退到指定版本
git reset d9b8d1f(git log 前面的编码) --hard
//撤销某个文件的操作(如git add code.c后,又不想添加code.c,可以用git reset来撤销)
git reset code.c

(四) 分支管理

git branch

//显示所有分支
git branch
//创建dev分支
git branch dev
//删除dev分支
git branch -d dev

git checkout

//切换到dev分支
git checkout dev

git merge

将一个分支合并到当前分支
当出现差异时,需要手动打开文件,选择要保留的内容,在git add git commit

//合并dev分支到当前分支
git merge dev

//一个有差异的文件的内容
$ cat git
<<<<<<< HEAD
master
=======
hello
>>>>>>> dev

(五)远程分支管理

git clone

克隆远程仓库

git clone https://github.com/schacon/ticgit

git remote

//查看有哪些remote
git remote -v
//添加remote
git remote add origin https://gitee.com/lingcb/onwork.git

git push

//将本地dev分支推送到远程master分支
git push origin dev:master
//删除远程仓库的一个分支
git push origin --delete serverfix

gite fetch

//拉取本地分支没有远程对应分支有的文件
git fetch origin

git pull

git pull runs git fetch with the given parameters and calls git merge to
merge the retrieved branch heads into the current branch

//拉去并合并 
git pull origin

(六)标签

//列出所有tag
git tag
//显示1.8.5 系列
git tag -l "v1.8.5*"
//添加标签
git tag -a v1.4 -m "my version 1.4"
//添加轻量标签
git tag v1.4-lw
//查看到标签信息和与之对应的提交信息
git show v1.4
//后期标签添加
git log --pretty=oneline
git tag -a v1.2 9fceb02

//创建完标签后你必须显式地推送标签到共享服务器上
git push origin v1.5
一次性推送很多标签
git push origin --tags

//删除本地标签
git tag -d v1.4-lw
//删除远程标签
git push origin :refs/tags/v1.4-lw
git push origin --delete <tagname>

结语

本文记录了常用的git命令,想更加深入的了解git,可以去读progo中文版在线文档

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值