git clone [-b 分支名] chenlong@http://project/admin.git不带-b参数默认master分支git clone http://project/admin.git
git clone –progress -v http://project/admin.gitgit.exe clone –progress -v “http://project/admin.git” “\192.168.0.105wwwother_userchenlongadmin”设置 -> git 编辑本地 .git/config 增加
[credential]
helper = storegit clone @http://project/admin.git admin2git checkout — application/core/MY_Exceptions.phpgit reset HEAD(commit) filegit reset –hard HEAD~3
会将最新的3次提交全部重置,就像没有提交过一样。git reset 版本号 — b.txt在Windows平台下面就有这个该死的行分隔符的问题,一般推荐git config –global core.autocrlf false
另外还可以git config –global core.safecrlf true
保证文件的行分隔符不会混杂。 然后以防万一重新git checkout或者git reset –hard一下================================================================================================================================
查看blob
git show 6ff87c4664 查看blob查看树
git ls-tree fb3a8bdd0ce 查看tree
注意:所有的文件的mode位都是644 或 755,这意味着Git只关心文件的可执行位.查看某个提交
git show -s –pretty=raw 2be7fcb476查看tag
git cat-file tag v1.5.0每个目录都创建了 tree对象 (包括根目录), 每个文件都创建了一个对应的 blob对象 . 最后有一个 commit对象 来指向根tree对象(root of trees), 这样我们就可以追踪项目每一项提交内容.
一个commit包含
一个tree
父对象 (parent(s))
作者author
提交者committer|– HEAD # 这个git项目当前处在哪个分支里
|– config # 项目的配置信息,git config命令会改动它
|– description # 项目的描述信息
|– hooks/ # 系统默认钩子脚本目录
|– index # 索引文件
|– logs/ # 各个refs的历史信息
|– objects/ # Git本地仓库的所有对象 (commits, trees, blobs, tags)
`– refs/ # 标识你项目里的每个分支指向了哪个提交(commit)。.git/refs/heads/master.git/refs/remotes/origin/master//add了没有commit
Changes to be committed:
(use “git reset HEAD…” to unstage)new file: yyy//原来的文件修改了 没有add
Changes not staged for commit:
(use “git add …” to update what will be committed)
(use “git checkout –…” to discard changes in working directory)modified: test//新文件没有add过的
Untracked files:
(use “git add…” to include in what will be committed)xxxgit config –global user.name “Scott Chacon”
git config –global user.email “schacon@gmail.com”Clone一个仓库
git clone http://www.kernel.org/pub/scm/git/git.git [dir]初始化一个新的仓库
git init除了用git add 命令,我还可以用
$ git commit -a
这会自动把所有内容被修改的文件(不包括新创建的文件)都添加到索引中,并且同时把它们提交。相当于add + commitGit跟踪的是内容不是文件
git add 不但是用来添加不在版本控制中的新文件,也用于添加已在版本控制中但是刚修改过的文件;
在这两种情况下, Git都会获得当前文件的快照并且把内容暂存(stage)到索引中,为下一次commit做好准备。例如:
修改了test ,git add 后 看
Changes to be committed:
modified: mmm再修改test git status看
Changes to be committed:
modified: mmmChanges not staged for commit:
modified: mmm分支与合并@基础
查看当前分支
git branch
创建
git branch test
切换到某个分支
git checkout branch
合并
git merge testGit鼓励大量使用分支:查看分支:git branch创建分支:git branch name切换分支:git checkout name创建+切换分支:git checkout -b name合并某分支到当前分支:git merge name 合并后的操作2个分支看起来都是一样的删除分支:git branch -d name修改的还没add的为 a版本,修改了add了的为 index版本,已经commit过的为 c版本,已经push的为 r版本。git diff
来找你当前工作目录和上次提交与本地索引间的差异 (即a版本和c版本)
git diff –cached
看在下次提交时要提交的内容(staged,添加到索引中) (即index版本和c版本)git diff master..test
git diff master…test 比父分支.gitignore 忽略文件不提示在Untracked files里git stash 存储某个时间状态http://gitbook.liuhui998.com/3_6.htmlhttp://gitbook.liuhui998.com/4_9.htmlGit的撤消操作 – 重置, 签出 和 撤消===================================9.24==================================================================
版本回退(未push出去之前):首先,Git必须知道当前版本是哪个版本,在Git中,用HEAD表示当前版本,也就是最新的提交“ 3628164…882e1e0”(注意我的提交ID和你的肯定不一样),上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。$ git reset –hard HEAD^
HEAD is now at ea34578 add distributed日志 git log 会清除掉又想回到最新的 git reflog查看历史 找到最新的 id
再回来
$ git reset –hard 3628164
HEAD is now at 3628164 append GPL命令git checkout — readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况:
一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
总之,就是让这个文件回到最近一次git commit或git add时的状态。撤销修改:
场景1:当你改乱了工作区某个文件的内容,想直接丢弃工作区的修改时,用命令git checkout — file。
场景2:当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步,第一步用命令git reset HEAD file,就回到了场景1,第二步按场景1操作。
场景3:已经提交了不合适的修改到版本库时,想要撤销本次提交,参考版本回退一节,不过前提是没有推送到远程库。git checkout其实是用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”。请问git rm –cache 和 git reset HEAD 的区别到底在哪里呢?在 git add <somefile> 之后,有的时候提示用“git rm –cache”来unstage,有的时候却是提示用“git reset HEAD”。如果要删除文件,最好用git rm file_name,而不应该直接在工作区直接rm file_name。
如果一个文件已经add到暂存区,还没有commit,此时如果不想要这个文件了,有两种方法:
1,用版本库内容清空暂存区,git reset HEAD
2,只把特定文件从暂存区删除,git rm –cache file>> 有的时候提示用“git rm –cache”来unstage
HEAD 里没有 <somefile> 时提示>> 有的时候却是提示用“git reset HEAD”。
HEAD 里有 <somefile> 时提示添加远端repo:
git remote add upstream https://github.com/linuxidc/first.git要关联一个远程库,使用命令git remote add origin git@server-name:path/repo-name.git;
关联后,使用命令git push -u origin master第一次推送master分支的所有内容;
此后,每次本地提交后,只要有必要,就可以使用命令git push origin master推送最新修改;
分布式版本系统的最大好处之一是在本地工作完全不需要考虑远程库的存在,也就是有没有联网都可以正常工作,而SVN在没有联网的时候是拒绝干活的!当有网络的时候,再把本地提交推送一下就完成了同步,真是太方便了!git push
-u, –set-upstreamhttps://github.com/linuxidc/first.git[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "upstream"]
url = https://github.com/linuxidc/first.git
fetch = +refs/heads/*:refs/remotes/upstream/*执行git push –set-upstream upstream master后[branch "master"]
remote = upstream
merge = refs/heads/mastergit remote add upstream https://github.com/linuxidc/first.git
git push -u upstream master
或
git push –set-upstream upstream master后
Branch master set up to track remote branch master from upstream.查看文件 cat .git/config 多了内容
[branch "master"]
remote = upstream
merge = refs/heads/master[root@chenlong first]# git push -u upstream master
Username for ‘https://github.com’: zxsz
Password for ‘https://zxsz@github.com’:
fatal: Authentication failedgit config –global push.default simple/matching下面说一下push.default matching和push.default simple的区别:push.default设置maching的意思是:git push 会把你本地所有分支push到名称相对应的远程主机上。这意味着可能你会在不经意间push一些你原本没打算push的分支。
push.default设置simple的意思是:git push仅仅把当前所在分支push到从当初git pull pull下来的那个对应分支上,另外,这个过程也会同时检查各个分支的名称是否相对应。[root@VM_44_174_CentOS first]# git push github master
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/linuxidc/first.git/info/refsgit remote set-url github https://github.com/linuxidc/first.gitssh-keygen -t rsa -C “chenlongtest_txyun”[remote "origin"]
fetch = + refs/heads/*:refs/remotes/origin/*
url = https://github.com/linuxidc/first.giturl = git@github.com:linuxidc/first.gitgit log –graph –pretty=onelinehttps://www.kernel.org/pub/software/scm/git/centos 安装报错
make[1]: *** Error 2
yum install perl-ExtUtils-MakeMaker package
/bin/sh: msgfmt: command not found
yum install gettext-develgit branch –merged
git branch –no-merged 查看尚未合并的工作
git branch -D test 强制删除分支用于有修改未commit的情况
git stash 存储当前现场
git stash listgit stash apply stash@{0}
git stash drop来删除
等同于
git stash pop当手头工作没有完成时,先把工作现场git stash一下,然后去修复bug,修复后,再git stash pop,回到工作现场。git merge –no-ff -m “merged bug fix 101″ issue-101因此,多人协作的工作模式通常是这样:首先,可以试图用git push origin branch-name推送自己的修改;如果推送失败,则因为远程分支比你的本地更新,需要先用git pull试图合并;如果合并有冲突,则解决冲突,并在本地提交;没有冲突或者解决掉冲突后,再用git push origin branch-name推送就能成功!如果git pull提示“no tracking information”,则说明本地分支和远程分支的链接关系没有创建,用命令git branch –set-upstream branch-name origin/branch-name。这就是多人协作的工作模式,一旦熟悉了,就非常简单。建议远程的 分支
git checkout -b branch-name origin/branch-name
建立本地分支和远程分支的关联,使用git branch –set-upstream branch-name origin/branch-name[chenlong@MD101 first]$git checkout -b dev3 origin/dev3
fatal: Cannot update paths and switch to branch ‘dev3′ at the same time.
Did you intend to checkout ‘origin/dev3′ which can not be resolved as commit?
[chenlong@MD101 first]$git branch dev3
git checkout dev3git push origin –deletegit log –pretty=oneline –abbrev-commit标签:
git tag 查看标签名称列表
git tag 标签名
git tag 标签名 commit版本号
git show 标签名还可以创建带有说明的标签,用-a指定标签名,-m指定说明文字:$ git tag -a v0.1 -m “version 0.1 released” 3628164
git tag -s v0.2 -m “version 0.1 released” 3628164 -s gpl加密git tag -d v0.1
git push origin v1.0
git push origin –tags 推送所有如果标签已经推送到远程,要删除远程标签就麻烦一点,先从本地删除:[chenlong@MD101 first]$git tag -d v0.7
Deleted tag ‘v0.7′ (was feb7a94)
然后,从远程删除。删除命令也是push,但是格式如下:[chenlong@MD101 first]$git push origin :refs/tags/v0.7 有空格
To git@github.com:linuxidc/first.git
- [deleted] v0.7自定义
git config –global color.ui true
.gitignore文件git config –global alias.unstage ‘reset HEAD’
git unstage test.py 等同于
git reset HEAD test.pygit config –global alias.lg “log –color –graph –pretty=format:’%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset’ –abbrev-commit”搭建git服务器如果希望ssh公钥生效,.ssh目录的权限必须是0700, .ssh/authorized_keys文件权限必须是0600。git:x:1000:1000::/home/git:/usr/bin/git-shellgit clone git@203.195.207.137:/data/git_res/test.gitUbuntu完美安装搭建Git服务器 http://www.linuxidc.com/Linux/2015-07/120616.htmGitHub 教程系列文章: GitHub 使用教程图文详解 http://www.linuxidc.com/Linux/2014-09/106230.htm Git 标签管理详解 http://www.linuxidc.com/Linux/2014-09/106231.htm Git 分支管理详解 http://www.linuxidc.com/Linux/2014-09/106232.htm Git 远程仓库详解 http://www.linuxidc.com/Linux/2014-09/106233.htm Git 本地仓库(Repository)详解 http://www.linuxidc.com/Linux/2014-09/106234.htm Git 服务器搭建与客户端安装 http://www.linuxidc.com/Linux/2014-05/101830.htm Git 概述 http://www.linuxidc.com/Linux/2014-05/101829.htm 分享实用的GitHub 使用教程 http://www.linuxidc.com/Linux/2014-04/100556.htm Ubuntu下Git服务器的搭建与使用指南 http://www.linuxidc.com/Linux/2015-07/120617.htmGit 的详细介绍:请点这里
Git 的下载地址:请点这里本文永久更新链接地址