git使用

2019-02-20  本文已影响0人  1234yws

git工作原理

操作原则: 所有新添加/删除/修改的文件 必须先添加到暂缓区,然后才能提交到HEAD指向的当前分支中

git指令

1.初始化本地仓库

git init

2.添加到暂缓区

git add .

3.提交

git commit -m '注释'

4.提交服务器

git push

5.查看当前文件状态

git status

红色:代表没有添加到暂缓区

绿色:代表已经添加到暂缓区,等待提交

6.添加tag并上传tag

git tag 0.0.1
git push --tags

7.本地从服务器更新代码

git pull

8.下载工作区代码

git clone 代码仓库地址

9.日志查看

git log
git reflog  回退使用该方法得到的版本号时不会丢失历史的所有版本

commit 9f5f05b679c6de951df5d2713620cc666f2a10ca
此处为提交后git生成的版本号

10.版本回退

git reset —hard HEAD 重置到当前版本
git reset —hard HEAD^^ 重置到上上个版本
git reset ——hard HEAD2 重置到往上2个版本
git reset —hard 七位版本号 重置到指定版本::
此处版本号为日志查看中的commit前七位

11.下载工作区代码

git clone 代码仓库地址

版本备份

在git中不是通过拷贝代码来解决备份和开启分支的 git 直接打标签, 通过控制head指向,来回到任一版本

1.版本打tag标签

git tag -a v1.0 -m '标记为v1.0版本'

2.将tag标签上传到共享库

git push origin v1.0

修改已经上线的bug

1.切换到上线版本的分支,根据v1.0版本建立新分支v1.0fixbug并切换到此分支

git checkout v1.0 -b v1.0fixbug::

2.提交

git add .
git commit -m “修复bug”

3.打tag标签作备份,并且上传服务器

git tag -a v1.1 -m “1.1版本备份”
git push origin v1.1
git push origin v1.0fixbug

4.合并分支

 git branch -r
 git checkout master
 git merge origin/v1.0fixbug -m “合并分支”
 git add .
 git commit -m “合并分支”
 git push
  git branch -r -d origin/v1.0fixbug

  git tag

git指令集

1、 git+下边命令

clone

Clone a repository into a new directory
将存储库克隆到新目录中

init

Create an empty Git repository or reinitialize an existing one
创建一个空的Git存储库或重新初始化一个现有的存储库

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
从工作树和索引中删除文件

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
显示工作树状态

branch

List, create, or delete branches
列出、创建或删除分支

checkout

Switchbranches 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
创建、列表、删除或验证使用GPG签名的标记对象

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
更新远程引用和相关对象
上一篇下一篇

猜你喜欢

热点阅读