git实用命令集锦

来源:互联网 发布:美图拼图软件 编辑:程序博客网 时间:2024/05/17 04:28

配置用户名、邮件:

$ git config --global user.name "Your Name"

$ git config --global user.email "email@example.com"


忽略某些文件:(如果不管用,就放到项目根目录下)
~/.gitconfig


忽略stage步骤,直接提交:
$ git commit -a -m 'added new benchmarks'


删除文件(同时从仓库和文件系统删除):
$ git rm -f grit.gemspec


移动(或重命名)文件:
$ git mv file_from file_to


查看提交历史纪录:
$ git log --pretty=oneline


看最近两周的提交历史纪录:
$ git log --since=2.weeks


忘了提交某个文件:(下面的三条命令最终只是产生一个提交,第二个提交命令修正了第一个的提交内容)
$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend


丢弃修改:
$ git checkout -- benchmarks.rb


查看当前配置有哪些远程仓库:(如果有多个远程仓库,此命令将全部列出)
$ git remote -v


创建、切换分支:
$ git branch
$ git checkout testing


新建一个bug分支,fix之后,merge到master分支,并删除改bug分支:
$ git branch iss53
$ git checkout iss53
$ vim index.html
$ git commit -a -m 'added a new footer [issue 53]'
$ git checkout master
$ git merge iss53
$ git branch -d iss53
0 0
原创粉丝点击