git init
git config --global user.name "老船长"
git config --global user.email "[email protected]"
ssh-keygen -t rsa -C "[email protected]"
git remote add origin git@code.csdn.net:myname/test.git
git remote rm origin
git clone git@code.csdn.net:myname/test.git
git add <fileName> #提交一个文件
git add . #提交所有修改,add空格后一个点
git status
git commit –m 【Notes】
git push origin master
git checkout -- <filename> #撤销该文件当前修改,但是已经git add过的,这儿是搞不定的,要用下面的git reset
git reset HEAD <fileName>
$ git log --pretty=oneline -5
5f440158d902812ffbe0caae1e22d48b436f98c0 test2
ec7df86bf03fa3f12e7c6eb09767f24a9653eb3c aaa
74aaa9ea635a6884e06a9a62b749c3a85d20ef05 bug
e9c1644203a0947dc78f5bb45cdca7933a19da89 test
git reset --hard HEAD^ #最后的^,是指一个版本号,若要退回两个版本号,就^^,两个三个等等
或
git reset --hard HEAD~1 #这儿最后的1是指退回一个版本号
或
git reset --hard ec7df86bf03fa3f12 #这儿后面一串是上面第二行的ID,可以是版本号的一部分,但最少要6位或7位以上
git pull
git checkout -b dev #创建并切换分支,相当于下面两条
git branch dev #创建
git checkout dev #切换
git branch #查看所有分支,当前分支前面会标一个*号
git merge dev #合并分支工作内容,此操作要在add并commit后操作
git branch -d dev #删除分支,此操作要在合并后操作,否则原来的工作内容可能会丢失
git status #查看冲突内容
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
在push或pull时,若出现这样的错误,是因为本地分支与远程分支没有关连,用提示的命令关连起来即可,但要用你自己的分支名称,这里我只写成了master:
git branch --set-upstream-to=origin/master master
git reflog
git log #查看所有
git log -(N) #查看最近N条
git log --pretty=oneline -(N) #只看历史的序列号和概要
git log --pretty=format:'%h by %ce at %cd' #按格式,具体见下面
选项 说明
%H 提交对象(commit)的完整哈希字串
%h 提交对象的简短哈希字串
%T 树对象(tree)的完整哈希字串
%t 树对象的简短哈希字串
%P 父对象(parent)的完整哈希字串
%p 父对象的简短哈希字串
%an 作者(author)的名字
%ae 作者的电子邮件地址
%ad 作者修订日期(可以用 -date= 选项定制格式)
%ar 作者修订日期,按多久以前的方式显示
%cn 提交者(committer)的名字
%ce 提交者的电子邮件地址
%cd 提交日期
%cr 提交日期,按多久以前的方式显示
%s 提交说明
$ git log --pretty=format:'%h by %ce at %cd'
该命令将以“简短SHA-1 by 提交者 at 提交时间”的格式显示日志
Administrator@CTO MINGW64 /d/git/kaibuy (master)
$ git --help
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone 克隆库
init 创建并初始化库
work on the current change (see also: git help everyday)
add 提交暂存
mv 删除或改名一个文件或目录
reset 重置HEAD状态
rm 从暂存中删除文件
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log 显示日志
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit 提交暂存到工作流
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Forward-port local commits to the updated upstream head
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull 拉取并合并
push 提交本地修改到远程库
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
本文主要根据以下两个教程整理而成。
廖雪峰:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
阮一峰:http://www.ruanyifeng.com/blog/2014/06/git_remote.html