git 理解和使用

CREATE
Clone an existing repository
$ git clone ssh://[email protected]/repo.git
Create a new local repository
$ git init

LOCAL CHANGES
Changed files in your working directory
$ git status
Changes to tracked files
$ git diff
Add all current changes to the next commit
$ git add .
Add some changes in <file> to the next commit
$ git add -p <file>

Commit all local changes in tracked files
$ git commit -a
Commit previously staged changes
$ git commit
Change the last commit
Don‘t amend published commits!
$ git commit --amend

COMMIT HISTORY

Show all commits, starting with newest
$ git log
Show changes over time for a specific file
$ git log -p <file>
Who changed what and when in <file>
$ git blame <file>

BRANCHES & TAGS

List all existing branches
$ git branch -av
Switch HEAD branch
$ git checkout <branch>
Create a new branch based
on your current HEAD
$ git branch <new-branch>
Create a new tracking branch based on
a remote branch
$ git checkout --track <remote/bran-
ch>
Delete a local branch
$ git branch -d <branch>

Mark the current commit with a tag
$ git tag <tag-name>

UPDATE & PUBLISH

List all currently configured remotes
$ git remote -v
Show information about a remote
$ git remote show <remote>
Add new remote repository, named <remote>
$ git remote add <shortname> <url>
COMMIT HISTORY
MERGE & REBASE
Download all changes from <remote>,
but don‘t integrate into HEAD
$ git fetch <remote>
Download changes and directly
merge/integrate into HEAD
$ git pull <remote> <branch>
Publish local changes on a remote
$ git push <remote> <branch>
Delete a branch on the remote
$ git branch -dr <remote/branch>

Publish your tags

$ git push --tags

MERGE & REBASE

Merge <branch> into your current HEAD
$ git merge <branch>
Rebase your current HEAD onto <branch>
Don‘t rebase published commits!
$ git rebase <branch>
Abort a rebase
$ git rebase --abort
Continue a rebase after resolving conflicts
$ git rebase --continue
Use your configured merge tool to
solve conflicts
$ git mergetool
Use your editor to manually solve conflicts
and ( after resolving) mark file as resolved
$ git add <resolved-file>
$ git rm <resolved-file>

UNDO

Discard all local changes in your working
directory
$ git reset --hard HEAD
Discard local changes in a specific file
$ git checkout HEAD <file>
Revert a commit (by producing a new commit
with contrary changes)
$ git revert <commit>
Reset your HEAD pointer to a previous commit
...and discard all changes since then
$ git reset --hard <commit>
...and preserve all changes as unstaged
changes
$ git reset <commit>
...and preserve uncommitted local changes
$ git reset --keep <commit>

时间: 2024-08-28 20:54:02

git 理解和使用的相关文章

Git理解

Git 1,Git是分布式版本控制工具,是用来做版本控制的. 2,Git的核心思想是分布式,快照,状态区,分支,需要对这几个部分好好理解一下. 3,Git的安装与配置(这部分在网上有较多教程,就忽略这部分). 4,Git的一些基本命令行操作,看这里http://www.cnblogs.com/feng-ye/p/5988091.html. (git命令行补充: git diff 查看发生变化的文件的具体变化(diff是查看变化的命令) git diff HEAD^/HEAD^^ 查看当前版本与上

Git理解笔记1

所读书目: http://www.kancloud.cn/kancloud/progit/70165 一.概念 版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.可以对任何类型的文件进行版本控制. 版本控制系统-version control system. 有了它你就可以将某个文件回溯到之前的状态,甚至将整个项目都回退到过去某个时间点的状态,你可以比较文件的变化细节,查出最后是谁修改了哪个地方,从而找出导致怪异问题出现的原因,又是谁在何时报告了某个功能缺陷等等. 使

git管理和自动部署项目

当一个项目需要纳入到版本控制的时候,选择的工具还是比较多的,最常见的就是工具有CVS,SVN,GIT等.在平时的开发中视情况而定,从来就没有最好的版本控制工具,只有最适合的工具.在这里我习惯用git来管理自己的项目,当然之前使用svn管理的,但是当用了git工具就不愿意再用其它的工具来管理.这里除了习惯之外,git的很多功能是svn不具备的,最简单的就是离线提交,用git管理的项目你会发现整个项目的大小变化不大,不像svn那样每个目录又有一个.svn 的目录,而且会使项目的变得很大.关于git与

git 使用入门

参考教程: 廖雪峰的官方网站 MY UBUNTU 安装: sudo apt-get install git GIT 理解: 选定的目录为git的工作区.该目录下的任何改动,git都会记录为工作区的修改,而不会提交至版本库(需add和commit操作). 提交至git的文件必须在该工作目录或者其子目录. git版本库包括stage(暂存区)和master(git默认创建的一个分支). 文件"add"操作只是将文件添加到git的暂存区,经"commit" 才将文件的更改

版本控制 - Git

此篇blog只是对http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 研读后的总结,还请各位看客细细品味原著. 一直以来,只是听说版本控制当推崇类似git这样的分布式版本控制,但之前使用的是SVN/subversion,而且也只限于会用add commit功能.所以连‘知其然’都没有做到.今天将对git理解整理如下,以便后用. 1. 设置机器身份: $ git config --gl

代码管理工具git使用来解决代码冲突管理

现在做软件产品项目,基本都用git来进行代码管理.相比SVN,git刚上手的人对git的使用的确感到很受伤.总结坑如下: 1.对git理解不透,不晓得git本地仓库,远程仓库的命令 2.SVN在Eclipse中的使用比git要舒服,不易出错. 但是项目代码使用git管理是大势所趋,不得不好好掌握.好在经过多次实践后,终于在git cmd中利用命令完美解决代码同步管理. 同步远程代码,遇到冲突的解决方法 1.方法一,采用远程文件覆盖本地文件. git pull git checkout <文件路径

迎接新未来

对于老师布置的关于这个git的作业,老实说,我是一脸茫然,与其说是对于这个git这个概念迷茫,不如说是对于构建之法这本书的茫然,当看到这本书时,我还以为就是一本理论书(就是对于编程的前世今生一个总括).我对于git理解: git,一个非常强大的版本管理工具. Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.它的使用流程不需要联机,可以先将对代码的修改,评论,保存在本机.等上网之后,再实时推送过去.同时它创建分支与合并分支更容易,推送速度也更快,配合Github提

2018年一名合格的web前端程序员应该会哪些技术

有朋友让小编说一说web前端在未来几年的发展趋向,对于这个问题,恕小编无能为力,web前端技术日新月异,更新非常快,谁也不能预料未来会发生些什么 小编也只能说在2018年,react native和jquery 的需求会减弱,ie10以下的兼容性要求显著降低,vr 有可能会归入前端技能树 为诸位总结了一些2018年web前端程序员应该掌握的前端技术,只有掌握了以下技术,才算一名合格的前端程序员 html, css, jQuery三者完全掌握,相信每个公司对于前端程序员都会有此要求,这些也是前端写

理解git

为了真正了解git,我们从底部.底层开始,了解git核心,知其然并知其所以然. 为什么要进行版本控制呢? 因为编写文件不可能一次到位,文件总是有不同的状态需要保存下来,方便以后出错回滚. git 是目前最先进的版本控制软件(VCS,version control system),它是linux之父Linus Torvalds的第二个作品. 正如git所命名的那样,是“愚蠢或不开心的人”,Linus评价“git is a British English slang for a stupid or