配置
配置用户信息
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
配置文本编辑器
git config --global core.editor vim
配置差异分析工具-- kdiff3,tkdiff,meld,xxdiff。emerge。vimdiff,gvimdiff。ecmerge,opendiff
git config --global merge.tool vimdiff
參看配置信息
git config --list
设置记住password(默认15分钟):
git config --global credential.helper cache
假设想自己设置时间,能够这样做:
git config credential.helper 'cache --timeout=3600'
长期存储password:git config --global credential.helper store


帮助
git help <verb>
 
初始化
仓库初始化
git init
git add *.c
git add README

git commit -m 'initial project version'

git remote add <shortname> <url>

git push [remote-name] [branch-name]

从现有仓库克隆

git clone git://github.com/schacon/grit.git
git clone git://github.com/schacon/grit.git mygrit
 
 
查看
查看文件状态
git status
查看当前文件和暂存区差异。当前文件上次提交文件差异
git diff
git diff <file>
查看暂存文件和上次提交差异
git diff --cached
參看历史
git log
log可视化

gitk

撤销工作空间  git checkout --
撤销暂存    git reset HEAD file
撤销commit git reset --hard commit_id  
撤销push git reset --hard <commit_id> git push --force
查看某个文件log git log file
比对某个文件在不同版本号的diff git diff  sha1 sha2 file

 


提交
提交更新
git commit
跳过使用暂存区提交
git commit -a -m 'added new benchmarks'


 

撤销
撤销提交
git commit --amend
取消暂存
git reset HEAD <file>
取消对文件的改动
git checkout -- <file>
 
文件操作
移除文件
git rm <file>
仅仅从跟踪清单中删除,文件不删除
git rm --cached readme.txt
移动文件
git mv file_from file_to
添加追踪文件
git add <file>
 
 
远程仓库
參看克隆的远程仓库
git remote -v
加入远程仓库(给远程路径取个别名)
git remote add [shortname] [url]
git remote add pb git://github.com/paulboone/ticgit.git
抓取远程仓库,不会合并
git fetch <remote>
git fetch pb
推送数据到远程仓库
git push <remote> <local_branch_name>
參看远程仓库信息
git remote show <remote>
更改仓库名称
git remote rename <old_remote> <new_remote>
git remote rename pb paul
 
 
分支
參看本地分支
git branch
查看远程分支
git branch -a
切换分支
git checkout <local-branch>
 
创建分支,从本地当前分支创建新的分支
git branch <new-local-branch>
创建分支,从本地其它分支创建新的分支
git branch <new-local-branch> <old-local-branch>
创建分支。从远程分支创建一个本地分支

git branch <new-local-branch> <remote>/<remote-branch>

创建分支,从本地分支创建一个远端分支

git push <remote> <old_local_branch>

git push <remote> <old_local_branch>:<new_remote_branch>

创建分支。从远端分支创建一个远端分支



创建并切换分支
git checkout -b <new-local-branch>
git checkout -b <new-local-branch> <old-local-branch>
git checkout -b <new-local-branch> <remote>/<remote-branch>
 
删除本地分支
git branch -d <local-branch>
删除远端分支
git push <remote-name> :<remote-branch>
 
合并本地其它分支到当前分支
git merge <local-branch>
合并远端到本地的当前分支
git pull [remote] <remote-branch>
 
创建远程分支。提交到远端分支

git push <remote> <local-branch>                   

取出我在本地的local-branch分支,推送到远程仓库的同名分支中去,远端无同名分支则创建同名分支

创建远程分支,提交到远端分支

git push <remote> <local-branch>:<remote-branch>   

取出我在本地的local-branch分支,推送到远程仓库的remote-branch分支中去,远端无remote-branch分支则创建remote-branch分支

 
设置本地分支跟踪远端分支

git branch --set-upstream-to=[remote]/<remote_branch> <local_branch>


tag

添加tag
git tag -a tag_name -m "comment" 在当前git版本号打上标签

git tag -a tag_name -m "comment" log_id 在已提交某个历史记录上打标签

切换的标签

git checkout tag_name

创建某个标签的分支

git checkout -b branch_name tag_name


设置gitdiff

http://blog.longwin.com.tw/2009/11/vimdiff-vs-git-diff-2009/

TortoiseGit使用入门 

http://keniclove.blog.163.com/blog/static/204959106201331292336552/

Github生成SSH公钥

通过配置ssh向github提交代码
http://www.linuxidc.com/Linux/2013-04/82949.htm


git配置多个密钥

http://www.cnblogs.com/fanyong/p/3962455.html设置gitdiff

转载于:https://www.cnblogs.com/yxysuanfa/p/6978450.html

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐