Git 的简单命令

  Git简单命令


  Git bash下输入
  git config --help  获得config帮助文档
  git config --global user.name yourname  设置和修改名字
  git config --global user.email yourmail@mail.com 设置和修改邮箱
  git config --global --add user.name yournewname  添加新的名字
  git config --global --add user.email yournewmail@mail.com 添加新的邮箱
  git config user.name 获得当前用户名
  git config user.email 获得当前邮箱
  git config --global --unset user.name yourname 删除一个用户名
  git config --global --unset user.email yourmail@mail.com  删除一个邮箱
  git config --list --global 查看所有的用户名,邮箱等配置
  git init my_repository 初始化仓库(自动创建.git文件)
  方式二: cd my_repository 然后 git init  效果遇上上面相同
   git init --bare my_bare_repository 初始化bare仓库(创建后没有.git文件)


  git cd c:/fileName  定位到某一文件夹
  git ls  查看当前文夹所有的文件
  git ls -l  查看当前文夹所有的文件 包含时间等信息
  cd ../.. 退回到默认repository目录
  cd ../ 退回一层,(类似于电脑中按了返回键)
  mkdir yourFilename 创建一个文件夹
  git clone old_reposity/new_reposity 克隆仓库
  git stauts 查看当前文件夹状态
  git add fileName 把fileName这个文件添加到暂存区
  git commit -m "initial commit" 把暂存区的文件提交的历史区
  touch newFile  创建新的文件
  vim fileName 修改文件的内容
         按 i 开始插入 Esc停止插入,停止插入后按shift + ; 输入 wq保存并退出,输入 q! 不保存退出
git rm fileName 删除工作区和暂存区中的文件引用
git rm cached fileName 仅删除暂存区中的文件引用
git reset HEAD fileName 还原某一文件的引用
git checkout fileName
clear 清空git dash
git mv file_a file_b 移动或重命名




.gitignore 命令的使用


*.type 忽略扩展名为type的文件
!notignorethisone.type  前面加!表示不忽略这个文件
dir/  忽略dir文件夹
filename  忽略某一文件
git config --global core.autocrlf (换行符三个值true,input,false 参考链接:http://blog.csdn.net/feng88724/article/details/11600375)


git branch newBranck   创建新的分支
git checkout newBranck  在这个新的分支上进行工作


查询历史记录(log)
      git log --all  查询所有历史记录
      git log 的一些参数
              --oneline 只显示一行 用法(git log --oneline)
     --decorate  commit引用的信息如tag信息
     --graph  图形化地表示
     --
 git tag "firstTag" b83e2b3 为这个b83e2b3 commit设置名为firstTag的tag
 git tag  查看tag
 git config --global alias.abc "log --oneline --decorate --graph --all" 为""中的命令起了一个abc的别名
 git checkout -b new_branch  git branch new_branch 和 git checkout new_branch的组合


 git stash save -a "stash first" 暂存区保存
 git stash list  查看保存的目录
 git stash pop -index stash@{0} 把stash中的内容恢复 加上--index参数表示同时恢复到暂存区(实测加不加--index没有发现区别,希望懂得人留言告诉我,谢谢)
 git stash apply stash@{0} 把stash中的内容恢复,不会删除stash,pop会删除stash
 git stash drop stash@{0}  手动删除stash
 git stash clear 一次清理多个stash
 以上 pop,apply,drop 如果后面没有加stash@{},默认对stash@{0}进行操作.


 git merge another_branch  把another_branch分支与当前分支合并
 git merge --abort 取消合并,什么时候使用不太清楚




 git show  显示提交记录,后面可以使用的参数有master,HEAD,哈希值,master^1,tag
 git diff  查看工作区与暂存区的区别
 git diff --cached 查看暂存区和历史区的区别
 git diff master^1 比较工作区和其他commit的差异
 git diff commit1 commit2  两个commit进行比较
 常用参数
           -- fileName 只比较这个文件在两个commit中的差异
  --color-words  显示不一样的文字用颜色区分
  --word-diff   显示不一样的文字用{}区分


撤销和修改:


git checkout -- fileName  撤销工作区的修改(也就是用暂存区覆盖工作区)
git checkout commit/branch/tag --  fileName  用历史的某一commit还原当前的工作区和暂存区
git reset commit还原暂存区 
git reset --hard  commit还原暂存区和工作区
            --mixed  commit还原暂存区(默认情况就是--mixed)
   --soft  commit不进行还原,尽把HEAD和分支引用指向当前的commit(hard,mixed也进行指向)
git revert  产生新的提交,覆盖之前的提交产生的修改


git clean -n 查看没有使用的文件
git clean -f 删除文件
git clean -n -X(大写) 加上大写X可以查看.gitignore忽略的文件保留其他的文件,不加-X将默认不查看.gitignore中忽略的文件
git clean -f -X 删除 .gitignore 忽略的文件
上面两个行命令如是用小写x,将忽略.gitignore文件的影响


git commit --amend
git rebase 线性合并查看与merge的区别 http://gitbook.liuhui998.com/4_2.html
git reset --hard commit 可以还原到这个commit
git reflog  (加上-10,显示近十条的记录)可以查看所有分支的所有操作记录(包括commit和reset的操作,及已经被删除的commit记录,git log则不能察看已经删除了的commit记录)



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值