就在刚才查看资料时候, 看见一句话, 写的特别好: 当我的才华撑不起我的梦想的时候, 应该安静下来学习

配上我最喜欢动漫的一个角色: 红莲

1. Git 初始化项目

1). 创建新的知识库

                echo "# study_git" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/renfanzi/study_git.git
git push -u origin master

2). 再次提交

          git add . 或者 git add test.py
git commit -m "..."
git push origin master

2. Git 创建分支

git checkout -b dev 创建dev分支, 并切换到dev分支中去

等同于:

git branch dev 创建dev 分支
git checkout dev 切换分支

git branch 查看当前分支

git branch -d dev 删除dev分支

3. Git 合并分支内容

        git merge dev  命令用于合并指定分支到当前分支, 如果当前在master分支, 那么这条命令就是把dev合并到master
注意:
如果文档有冲突, 需要修正冲突以后再上传

4. Git 回滚

1). git log 命令可以帮我们查看历史记录, 查看版本号, 如果觉得太眼花缭乱, 可以加上 --pretty=oneline

                ===========
root@corleone:/opt/code/my_code/git_study# git log
commit 6c73f83caaefbaa7d19ca583a27cfebcd6c6f071 (HEAD -> master, origin/master)
Author: root <root@localhost.localdomain>
Date: Tue Jul :: + two commit commit ffc485e22ca1748d28d83f817cb5d8abbd7a0a5f
Author: root <root@localhost.localdomain>
Date: Tue Jul :: + first commit
===========

2). 两种方式回滚

方法1:

git reset --hard HEAD^ 

(在Git中,用HEAD表示当前版本,也就是最新的提交ffc485e22c...(注意我的提交ID和你的肯定不一样),
上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。)

再次查看git log

                    -----------------------
root@corleone:/opt/code/my_code/git_study# git log
commit ffc485e22ca1748d28d83f817cb5d8abbd7a0a5f (HEAD -> master)
Author: root <root@localhost.localdomain>
Date: Tue Jul :: + first commit
root@corleone:/opt/code/my_code/git_study#
----------------------

已经回滚到上一级了

方法2:

git reset --hard 6c73f83caa 等同于上面

3). git 回滚到以前被掩盖覆盖的版本中

方法一:

只要上面的命令行窗口还没有被关掉,你就可以顺着往上找,找到那个commit 的commit ID,于是就可以指定回到指定版本

方法二:

git reflog ---> 作用: 记录你的每一次的命令

终端返回值:
====================
root@corleone:/opt/code/my_code/git_study# git reflog
6c73f83 (HEAD -> master, origin/master) HEAD@{0}: reset: moving to 6c73f83caa
6c73f83 (HEAD -> master, origin/master) HEAD@{1}: reset: moving to 6c73f83caa
ffc485e HEAD@{2}: reset: moving to HEAD^
6c73f83 (HEAD -> master, origin/master) HEAD@{3}: commit: two commit
ffc485e HEAD@{4}: commit (initial): first commit
===================

5. 常用命令

        git diff readme.md  查看文件被改变状态(以提交一次, 继续工作, 许久后忘记哪些地方修改了, 可以用这个命令)
======
root@corleone:/opt/code/my_code/git_study# git diff readme.md
diff --git a/readme.md b/readme.md
index e69de29..bca558b
--- a/readme.md
+++ b/readme.md
@@ -, +, @@
+asdfadsf
+
======
git reflog ---> 作用: 记录你的每一次的命令 git log 命令可以帮我们查看历史记录, 查看版本号 git reset --hard HEAD^
git reset --hard 6c73f83caa 等同于上面 git clone https://... 克隆项目

6. .gitignore 的作用

把要忽略的文件名填进去,Git就会自动忽略这些文件。

最新文章

  1. javascript的console.log用法
  2. Shell study note
  3. 再牛逼的梦想,也抵不住SB似的坚持
  4. 字典树(Trie)的java实现
  5. 今天分享一个抽奖的类Lottery
  6. Java在Windows的环境配置
  7. vs2005升级到vs2010相关问题
  8. linux下ntfs硬盘的加载
  9. 什么是Intent(意图)
  10. SqLite 使用 Dapper 查询INTEGER类型的主键问题
  11. 201521123085 《Java程序设计》 第2周学习总结
  12. eclipse汉化链接
  13. PHP 匿名函数使用技巧
  14. Entity Framework Core系列之DbContext(修改)
  15. sklearn pipeline
  16. How to monitor tempdb in MS SQL
  17. ARM 编译产生.map之RO RW ZI
  18. [20170728]oracle保留字.txt
  19. java中 this 关键字的三种用法
  20. Spring-Boot原理及应用布署

热门文章

  1. vue-webpack快速建立项目模板
  2. poj 1868 Antiarithmetic? 推断序列中是否有等差子序列
  3. rdesktop 源码安装
  4. 菜鸟学Java(九)——Servlet的基本配置
  5. calcite 理论
  6. 深度学习领域的Papers
  7. iOS应用管理(优化)
  8. Windows下使用第三方lua库
  9. 笔记本貌似好了(HP 450 卡)
  10. 【开发】MFC到Delphi的皮肤移植