GitHub备忘单

创建仓库----创建一个新的仓库或者从一个现有的仓库获取仓库

$ git init [project-name]

创建一个本地仓库并设置名字或者在本地文件夹中$git init

$ git clone [url]

下载一个项目以及它所有的版本历史

更改----检查已有的编辑并执行提交操作

$ git status

列出所有新建或者更改的文件,这些文件需要被提交

$ git diff

展示文件进行快照处理用于版本控制

$ git reset [file]

将文件移除暂存区,但是保留内容

$ git add [file]

将文件进行快照处理用于版本控制

$ git commit -m"[descriptive message]"

将文件快照永久的记录在版本历史中

批量更改----命名一系列承诺以及合并已完成的工作

$ git branch

列出当前仓库中所有的本地分支

$ git branch [branch-name]

新建一个分支

$ git checkout [branch-name]

切换到一个特定的分支上并更新工作目录

$ git merge [branch-name]

合并特定分支的历史到当前分支

$ git branch -d [branch-name]

删除特定分支

重构文件----重定位并移除历史版本

$ git rm [file]

从工作目录删除文件并暂存这次删除

$ git rm --cached [file]

从版本控制中移除文件,并在本地保存文件

$ git mv [file-original] [file-renamed]

更改文件名并准备提交

停止追踪----不包含临时文件和路径

*.log

build/

temp-*

文件字幕:.gitignore可以防止一些特定文件进入版本历史中

$ git ls-files --others --ignored --exclude --standard

列出所有项目中忽略的文件

保存历史更改----暂存一些未完成的更改 暂存=已藏匿(现在要切换分支机构为客户不断升级,但你不想提交你的工作,所以你会藏匿的变化。要推一个新的藏匿到您的堆栈,运行git stash命令)

你工作目录下的每一个文件都不外乎这两种状态:已跟踪或未跟踪。 已跟踪的文件是指那些被纳入了版本控制的文件,在上一次快照中有它们的记录,在工作一段时间后,它们的状态可能处于未修改,已修改或已放入暂存区。 工作目录中除已跟踪文件以外的所有其它文件都属于未跟踪文件,它们既不存在于上次快照的记录中,也没有放入暂存区。 初次克隆某个仓库的时候,工作目录中的所有文件都属于已跟踪文件,并处于未修改状态。

$ git stash

临时存储所有已更改的跟踪文件

$ git stash pop

重新存储所有最近被藏匿的文件

$ git stash list

列出所有被藏匿的更改

$ git stash drop

放弃所有最近藏匿的更改

查阅历史----浏览并检查项目文件的发展

$ git log

列出当前分支的版本历史

$ git log --follow [file]

列出文件的版本历史,包括重命名

$ git diff [first-branch] .... [second-branch]

展示两个不同分支的差异

$ git show [commit]

输入元数据以及特定commit的内容变化

撤销commit----擦除错误并更改历史

$ git reset [commit]

撤销所有commit后的commit,在本地保存更改

$ git reset --hard[commit]

放弃所有更改并回到某个特定的commit

同步更改----注册一个远程连接,交换仓库的版本历史

$ git fetch [remote]

下载远程仓库的所有历史

$ git merge [remote]/[branch]

合并远程分支到当前分支

$ git push [remote] [branch]

上传所有本地分支commit到github上

$ git pull

下载书签历史并合并更改

常用操作整理

commit:

git commit

git branch:

git branch <branchname>

git checkout <branchname>

git merge:

git merge <branchname>

merge the branchname to current branch

git rebase

take a series of commit records, copy them to another place

git rebase <another place>

current to another place

Git rebase <branchname1> <branchname2>

Copy name2 to name1

HEAD points to the latest record in the current branch

Split the head is means that let the HEAD points to the record rather than the branch name

Usint HEAD^ to move ahead

Git branch -f <branch> <place>

-f allows us to move the <branch> to <place>

Revert and reset

Git cherry-pick

Git rebase

个人常用:在文件夹中新建本地仓库并提交到GitHub

  1. cd path
  2. git init
  3. git add .
  4. git commit -m ‘message’
  5. git status
  6. git remote add origin respname
  7. git pull –rebase origin master将新建仓库里的readme文件合并到本地
  8. git push -u origin master 把本地仓库的项目推送到远程仓库(GitHub)

猜你喜欢

转载自www.cnblogs.com/shemlo/p/11608651.html