君陌离的博客

vuePress-theme-reco 君陌离    2018 - 2020
君陌离的博客 君陌离的博客

Choose mode

  • dark
  • auto
  • light
首页
我的作品
  • 项目橱窗
  • blog模板
分类
  • 数据库
  • CSS
  • 摘记
  • JS
  • Node
  • Vue
  • React
  • GIT
  • Promise
  • Liunx
  • Xshell
  • ajax
  • WINDOWS
  • Python
  • 随笔
  • 脚手架
  • node
  • 自动化
标签
笔记
时间线
About Me
  • 关于我
  • 赞赏
Contact
  • GitHub
  • QQ
author-avatar

君陌离

70

文章

90

标签

首页
我的作品
  • 项目橱窗
  • blog模板
分类
  • 数据库
  • CSS
  • 摘记
  • JS
  • Node
  • Vue
  • React
  • GIT
  • Promise
  • Liunx
  • Xshell
  • ajax
  • WINDOWS
  • Python
  • 随笔
  • 脚手架
  • node
  • 自动化
标签
笔记
时间线
About Me
  • 关于我
  • 赞赏
Contact
  • GitHub
  • QQ

GIT指令

vuePress-theme-reco 君陌离    2018 - 2020

GIT指令

君陌离 2020-08-07 GIT指令

GIT

git指令操作
应有尽有
let’s go!
......

# 初始化git流程

git init
1

# 添加文件

git add .  
# 添加文件,git add 文件路径(单个文件方式)
1
2

# 提交注释

git commit -m "sk"
1

# 设置远程主机

git remote add origin https://git.coding.net/QQ15994206180/WordPress.git
1

# 推送到远程主机

git push -u origin master
# 推送到远程主机,如果出现![rejected],说明初次使用git仓库,远程仓库与本地仓库不一致,需拉一下,使用命令git pull --rebase origin master(此命令前提是本地新建仓库应为空仓库),在推送就OK了.下次直接使用git push就OK了.
1
2

# 本地仓库关联远程分支

$ git branch --set-upstream-to=origin/master master
# 本地仓库关联远程分支(就可以直接使用Git pull,Git push等指令)
1
2

# 修改远程地址

git remote set-url origin https://e.coding.net/QQ15994206180/blog.git
1

# 分支匹配

git config --global push.default matching
1

# git全局name,email修改

git credential-manager uninstall
1

# 配置用户名指令

git config --global user.name 用户名
1

# 配置邮箱指令

git config --global user.email 邮箱地址
1

# 查看配置的用户名和邮箱

git config --list
1

# 查看指定配置项的值

git config user.name

git config user.email
1
2
3

# git 编辑模式退出

":wq+enter键"
1

# 撤回操作

git reset
# 撤回git add .操作
1
2

# 查看所有分支的所有操作记录

git reflog
1

# 根据版本号撤回版本

git reset --hard "版本号"
1

# 撤销本地版本修改

git checkout .
1

# 创建分支

git branch sk
1

# 切换分支

git checkout sk

git checkout -b sk
# 创建sk分支,并切换到sk分支
1
2
3
4

# 记住用户名和密码

# GIT之https或http方式设置记住用户名和密码的方法

# 设置记住密码(默认15分钟):
git config --global credential.helper cache

# 如果想自己设置时间,可以这样做:
git config credential.helper 'cache --timeout=3600'
# 这样就设置一个小时之后失效

# 长期存储密码:
git config --global credential.helper store

# 增加远程地址的时候带上密码也是可以的。(推荐)
http://yourname:password@git.oschina.net/name/project.git
# 补充:使用客户端也可以存储密码的。

# 如果你正在使用ssh而且想体验https带来的高速,那么你可以这样做: 切换到项目目录下 :
cd projectfile/
# 移除远程ssh方式的仓库地址
git remote rm origin

# 增加https远程仓库地址
git remote add origin https://yourname:password@git.oschina.net/name/project.git
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

# 查看操作

# 没提交之前,查看更改内容
git diff
# 查看所有

git diff 文件名
# 单个文件

# 查看提交记录

git log git log <file> 
# 查看该文件每次提交记录

git log -p <file>
# 查看每次详细修改内容的diff

git log -p -2 
# 查看最近两次详细修改内容的diff

git log --stat 
# 查看提交统计信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

git push origin master和git push有什么区别?

  • master是主分支,还可以建一些其他的分支用于开发。
  • git push origin master的意思就是上传本地当前分支代码到master分支。git push是上传本地所有分支代码到远程对应的分支上。
欢迎来到 您的站点名称($site.title)
看板娘