GIT简易的命令行入门教程

GIT简易的命令行入门教程

Jerome Xiong
Jerome Xiong

Git 是当今最流行的分布式版本控制系统,掌握常用命令行操作是开发者的基本功。本文整理了从仓库初始化到日常提交流程、从分支管理到 submodule 的常用命令,适合作为速查手册。

Git 全局设置:

1git config --global user.name "jeromexiong"
2git config --global user.email "1540428743@qq.com"

创建 git 仓库:

1mkdir bookclub
2cd bookclub
3git init
4touch README.md
5git add README.md
6git commit -m "first commit"
7git remote add origin https://gitee.com/jeromexiong/bookclub.git
8git push -u origin master

已有仓库?

1cd existing_git_repo
2git remote add origin https://gitee.com/jeromexiong/bookclub.git
3git push -u origin master
4
5error: fatal: refusing to merge unrelated histories
6// 把两段不相干的 分支进行强行合并
7git pull origin master --allow-unrelated-histories
1git checkout . && git clean -df #本地所有修改的。没有的提交的,都返回到原来的状态
2git stash #把所有没有提交的修改暂存到stash里面。可用git stash pop回复。
3git reset --hard HASH #返回到某个节点,不保留修改。
4git reset --soft HASH #返回到某个节点。保留修改
5
6git status #查看git状态
7git add filename #暂存文件 . 当前所有
8git rm --cached filename #取消暂存文件
9git rm -r --cached . #取消当前所有暂存文件
10git rm filename #删除文件
11git checkout filename #取消文件修改
12git commit -m 'commit msg'

git tag

修改.gitignore文件并让其生效

1# 重置提交
2git reset --hard commit
3
4# 下载git
5git clone <git url> -b <branch or tag>
6
7git rm -r --cached . 
8git add .
9
10git commit -m "Remove ignored files"

submodule

  1. 添加submodule
1git submodule add 仓库地址 路径
  1. 下载的工程带有submodule
1git submodule update --init --recursive
  • 标题: GIT简易的命令行入门教程
  • 作者: Jerome Xiong
  • 创建于: 2019-06-01 18:00
  • 链接: https://jeromexiong.github.io/2019/06/01/工具/GIT简易的命令行入门教程/
  • 版权声明:本文章采用 CC BY-NC-SA 4.0 进行许可。
评论