A git cheatshell based on the book: http://www.git-scm.com/book/en/v2.

Repository Configuration

git init - initialize an empty repository

git clone https://github.com/libgit2/libgit2 - clone the remote repository to a local target named libgit2

git clone https://github.com/libgit2/libgit2 mylibgit - clone the remote repository to a local target named mylibgit

/etc/gitconfig: contains values for every user on the system and all their repositories. git config --system will read and write from this file

~/.gitconfig: specific to your user. git config --global will read and write from this file

.git/config: specific repository configuration

git config --global user.name "Jonathan Lim" - set global user to "Jonathan Lim"

git config --global user.email jonathanlim@example.com

git config --global core.editor emacs - set your default editor

Track Changes

git status - to view current status of your working directory

git add README -  add the file README to staging area

git commit - commit changes in staging area. In this case, a text editor will pop up to input commit comments

git commit -m "commit message" - commit with commit message

git commit -a -m "commit message" - makes Git automatically stage every file that is already tracked before doing the commit

git commit --amend - Amend the last commit, e.g. commit more files/modify the commit message

git rm - remove the file from the working directory and from the index. If the file is modified already and added to the index. Use git rm -f to force the removal

git rm --cached - keep the file in the working directory but remove it from the index

git mv file_from file_to - rename a file in Git

git log - list all the commits made in that repository

git log -p -2 - shows difference introduced in each commit. -2 limits the output to only the last two commits

git log --pretty="format string" - format the log

git log -Sfunction_name - Find the last commit that add/remove a reference to a specific function

git diff - to see what you've changed but not yet staged

git diff --staged -  to see what you've staged that will go into your next commit

git diff --cached - just like git diff --staged

git checkout -- [file] - discard all the changes on the file since last commit

Working with Remote

git remote - show remote repository name

git remote -v - show remote repository name and URL

git remote add [short name] [url] - Add a new remote Git repository as a shortname

git fetch [short name] - pull down all the data from that remote project. After doing this, should have references to all the branches from the remote. Note that, git fetch just pulls the data to the local repository - it doesn't do the merge automatically.

git push [short name] [branch name] - push local branch to remote server

git remote show [short name] - see more information about a particular remote

git remote rename [old short name] [new short name] - change a remote's shortname

git remote rm [short name]

Tagging

Typically people use this functionality to mark release points (v1.0, and so on)

  • Lightweight tag: like a branch that doesn't change (it's just a pointer to a specific commit)
  • Annotated tag: stored as full objects in the Git database

git tag - list the available tags

git tag -l [pattern] - search for tags with a particular pattern

git show [tag] - show tag data along withe the commit that was tagged

git tag -a [tag] -m [message] - create a annotated tag

Branching

Tracking branch/upstream branch - local branches that have a direct relationship to a remote branch.When you clone a repository, it generally automatically creates a  master branch that tracks  origin/master

git branch [branch name] - create a new branch

git branch -v - show last commit on each branch

git branch --merged|--no-merged - show which branches are already merged/not merged into the current branch

git branch -d [branch] - delete a branch

git branch -u [remote branch, e.g.origin/hotfix] -

git log --oneline --decorate - show where the HEAD pointer is point

git log --online --decorate --graph --all - show the history of the commits, showing where the branch pointers are and how history has diverged

git checkout [branch name] - switch to an existing branch

git checkout -b [new branch name] - create a new branch and switch to the new one

git checkout -b [branch] [remote branch, e.g. origin/hotfix] - create a local branch that mapping to the remote branch

git merge [branch] - merge the target branch into current branch

git push [short name, e.g. origin] [local branch]:[branch on the remote] - push local branch to the branch on the remote project

git branch -vv - show what tracking branches you have set up

git rebase [branch] - take the patch of the changes that was introduced in C4 and reapply it on top of C3.

git rebase [base branch] [topic branch] - check out the topic branch and replay it onto the base branch

Git Cheatshell - Pro Git的更多相关文章

  1. Pro Git 第一章 起步 读书笔记

    Pro Git 笔记 第1章 起步 1.文件的三种状态. 已提交:文件已经保存在本地数据库中了.(commit) 已修改:修改了某个文件,但还没有提交保存.(vim) 已暂存:已经把已修改的文件放在下 ...

  2. 《Pro Git》阅读随想

    之前做版本管理,我使用最多的是SVN,而且也只是在用一些最常用的操作.最近公司里很多项目都开始上Git,借这个机会,我计划好好学习一下Git的操作和原理,以及蕴含在其中的设计思想.同事推荐了一本< ...

  3. Pro Git(中文版)

    Pro Git(中文版) 返回 Git @ OSC 目录 1.起步 1.1 关于版本控制 1.2 Git 简史 1.3 Git 基础 1.4 安装 Git 1.5 初次运行 Git 前的配置 1.6 ...

  4. 《Pro Git》笔记3:分支基本操作

    <Pro Git>笔记3:Git分支基本操作 分支使多线开发和合并非常容易.Git的分支就是一个指向提交对象的可变指针,极其轻量.Git的默认分支为master. 1.Git数据存储结构和 ...

  5. 【Tools】Pro Git 一二章读书笔记

    记得知乎以前有个问题说:如果用一天的时间学习一门技能,选什么好?里面有个说学会Git是个很不错选择,今天就抽时间感受下Git的魅力吧.   Pro Git (Scott Chacon) 读书笔记:   ...

  6. Pro Git CN Plus

    Git — The stupid content tracker, 傻瓜内容跟踪器.Linus 是这样给我们介绍 Git 的. Git 是用于 Linux 内核开发的版本控制工具.与常用的版本控制工具 ...

  7. 《Pro git》

    可以通过阅读 CODING 工程师参与翻译的 <Pro Git> 进一步掌握 Git 版本控制系统. https://git-scm.com/book/zh/v2

  8. 《Pro Git》轻松学习版本控制

    转自 https://kindlefere.com/post/333.html 什么是“版本控制”?我为什么要关心它呢?版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.在 ...

  9. [Git00] Pro Git 一二章读书笔记

    记得知乎以前有个问题说:如果用一天的时间学习一门技能,选什么好?里面有个说学会Git是个很不错选择,今天就抽时间感受下Git的魅力吧.   Pro Git (Scott Chacon) 读书笔记:   ...

随机推荐

  1. scss牛刀小试:解决css中适配浏览器前缀问题

    在css中为适配浏览器,新特性总加 -webkit,-o, -moz 来适配浏览器,写的烦心,看着也臃肿,让css可读性降低,下面以阴影为例,如何使用scss让我们的css看起来更简洁. 本人使用的I ...

  2. AIR Native Extension for iOS 接入第三方sdk 如何实现 AppDelegate 生命周期

    作者:Panda Fang 出处:http://www.cnblogs.com/lonkiss/p/6492385.html 原创文章,转载请注明作者和出处,未经允许不可用于商业营利活动 去年到今年做 ...

  3. JavaScript(一) 对象基础

    1.定义类或对象 1.1 混合的构造函数/原型方法 用构造函数定义对象的所有非函数属性,类似于Java的构造方法.用原型方法定义对象的函数属性(方法).这种方法是使用比较广泛的定义类或对象的方法. / ...

  4. Wampserver由橙变绿的解决过程

    因为C盘的内存问题,就重装了win7系统,那么就面临着很对软件要重新进行安装,安装wampserver时,再次遇到了服务器的图标一直是橙色的而不变绿色,安装包地址: http://download.c ...

  5. 《转化:提升网站流量和转化率的技巧》:结合市场营销六阶段理论,以SEM为手段,提高网站转化率的技巧

    全书结合市场营销的六阶段理论,讲述各阶段的营销方面的要点和网站上吸引访客的技巧.举了一些例子,列举了一些工具.当然都是美国市场中的例子和网站优化的工具. 没有太多的新意.没看过相关图书的可以看看.

  6. java研发常见问题总结2

    1. String.StringBuffer与StringBuilder之间区别 关于这三个类在字符串处理中的位置不言而喻,那么他们到底有什么优缺点,到底什么时候该用谁呢?下面我们从以下几点说明一下 ...

  7. 关于使用Encoding转码的问题,以及StreamWriter的小应用

    StreamWriter write = new StreamWriter("../../test2.txt"); write.WriteLine("中国123巴西red ...

  8. 使用navigate导出表数据

    以下内容不算技术贴,只能算是技巧贴,要做的一个操作,从数据库A中把元素A1表,导入到数据库B中B1表,且,A1表的数据是部分导出,那么有两种方法进行导出 方法1: 选择数据表,右键,选择“转存储sql ...

  9. java 使用hashmap一个键对应多值的方法

    背景:在你使用map对象时,你可能会有一个key,对应多个值的需求 实现: import java.util.ArrayList; import java.util.HashMap; import j ...

  10. ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id

    远程删除key ssh-keygen -f "~/.ssh/known_hosts" -R 192.168.0.34 如果还是不可以,通过 ssh-keygen 重新生成key