Git常用命令
来源:互联网 发布:数据库基本编程foxpro 编辑:程序博客网 时间:2024/06/07 21:57
Git常用命令
最先接触的版本管理软件是SVN,当时觉得挺好用的,后来需要切换到Git上,刚接触Git时觉得它挺麻烦的,特别在处理冲突方面与SVN不太一样。也找了一些文章看Git的命令,感觉每篇文章对Git命令的解释都不清不楚的,当然这也是因为对Git熟悉造成的。随着在工作中频繁的使用,逐渐对这些命令熟悉与理解。这里把这些常用命令记录下来主要是为了备忘。
1. 配置
列出当前配置:
git config --list
列出repository配置:
git config --local --list
列出全局配置:
git config --global --list
列出系统配置:
git config --system --list
设置用户名:
git config --global user.name "[firstname lastname]"
设置用户邮箱:
git config --global user.email "[valid-email]"
设置git命令输出为彩色:
git config --global color.ui auto
设置git使用的文本编辑器为vi:
git config --global core.editor vi
2. 创建
复制一个已创建的仓库:
# 通过SSH git clone ssh://user@domain.com/repo.git# 通过HTTP git clone http://domain.com/user/repo.git
创建一个新的本地仓库:
git init
本地修改
显示工作路径下已修改的文件:
git status
显示与上次提交版本文件的不同:
git diff
把当前所有修改添加到下次提交中:
git add.
把对某个文件的修改添加到下次提交中:
git add -p <file>
提交本地的所有修改:
git commit -a
提交之前已标记的变化:
git commit
附加消息提交:
git commit -m 'message here'
提交并将提交时间设置为之前的某个日期:
git commit --date="`date --date='n day ago'`" -am "Commit Message"
修改上次提交:
请勿修改已发布的提交记录!
git commit --amend
修改上次提交的committer date:
GIT_COMMITTER_DATE="date" git commit --amend
修改上次提交的author date:
git commit -amend --date="date"
把当前分支中未提交的修改移动到其他分支:
git stashgit checkout branch2git stash pop
将stashed changes应用到当前分支:
git stash apply
删除最新一次的stashed changes:
git stash drop
3. 提交历史
从最新提交开始,显示所有的提交记录(显示hash,作者信息,提交的标题和时间):
git log
显示所有提交(仅显示提交的hash和message):
git log --oneline
显示某个用户的所有提交:
git log --author="username"
显示某个文件的所有修改:
git log -p <file>
仅显示远端
git log --oneline <origin/master> <remote/master> --left-right
谁在什么时候修改了文件的什么内容:
git blame <file>
显示reflog:
git reflog show
删除reflog:
git reflog delete
4. 分支与标签
列出所有的分支:
git branch
列出所有的远端分支:
git branch -r
切换分支:
git checkout <branch>
创建并切换到新分支:
git checkout -b <branch>
基于当前分支创建新分支:
git branch <new-branch>
基于远程分支创建新的可追溯的分支:
git branch --track <new-branch> <remote-branch>
删除本地分支:
git branch -d <branch>
强制删除一个本地分支:
将丢失未合并的修改!
git branch -D <branch>
给当前版本打标签:
git tag <tag-name>
给当前版本打标签并附加消息:
git tag -a <tag-name>
5. 更新与发布
列出当前配置的远端:
git remote -v
显示远端的信息:
git remote show <remote>
添加新的远端:
git remote add <remote> <url>
下载远端版本,但不合并到HEAD中:
git fetch <remote>
下载远端版本,并自动与HEAD版本合并:
git remote pull <remote> <url>
将远端版本合并到本地版本中:
git pull origin master
以rebase方式将远端分支与本地合并:
git pull --rebase <remote> <branch>
将本地版本发布到远端:
git push remote <remote> <branch>
删除远端分支:
git push <remote> --delete <branch>
发布标签:
git push --tags
6. 合并与重置(Rebase)
将分支合并到当前HEAD中:
git merge <branch>
将当前HEAD版本重置到分支中:
请勿重置已发布的提交!
git rebase <branch>
退出重置:
git rebase --abort
解决冲突后继续重置:
git rebase --continue
使用配置好的merge tool解决冲突:
git mergetool
在编辑器中手动解决冲突后,标记文件为已解决冲突
:
git add <resolved-file>git rm <resolved-file>
合并提交:
git rebase -i <commit-just-before-first>
7. 撤销
放弃工作目录下的所有修改:
git reset --hard HEAD
移除缓存区的所有文件(如,撤销上次git add):
git reset HEAD
放弃某个文件的所有本地修改:
git checkout HEAD <file>
重置一个提交:
git revert <commit>
将HEAD重置到指定的版本,并抛弃该版本之后的所有修改:
git reset --hard <commit>
用远端分支强制覆盖本地分支:
git reset --hard <remote/branch>
将HEAD重置到上一次提交的版本,并将之后的修改标记为未添加到缓存区的修改:*
git reset <commit>
将HEAD重置到上一次提交的版本,并保留未提交的本地修改:
git reset --keep <commit>
删除添加.gitignore
文件前错误提交的文件:
git rm -r --cachedgit add .git commit -m "remove file"
- git 常用命令
- Git常用命令
- git 常用命令
- git 常用命令
- git 常用命令
- git 常用命令
- GIT常用命令
- git 常用命令
- git 常用命令
- Git 常用命令
- git 常用命令
- Git常用命令
- Git常用命令
- git 常用命令
- Git 常用命令
- git常用命令
- git 常用命令
- Git 常用命令
- android学习(二十三) 访问联系人数据
- [kuangbin带你飞]专题十二 基础DP1 C
- HDU
- Java集合之LinkedHashMap
- cmake笔记
- Git常用命令
- 网页开发入门之解决数据分页问题
- 打印所有出栈序列(指定进栈序列的顺序)
- linux下安装mysql
- Eclipse 安装反编译插件jadclipse(经验总结)
- POJ 1308 判断是否为一颗树
- 《PCL点云库学习&VS2010(X64)》Part 34 旋转平移矩阵用法
- idea使用方法
- 合并无序数组