常用的Git命令

我的常用的Git命令


Git仓库配置常用

1. clone

克隆一份远程的Git版本库

git  clone  git://github.com/someone/some_project.git   some_project

这句话会把链接上的Git库直接复制到当前目录some_project文件夹下


2. init

在本地建立一个Git工作目录

git init

##3. remote ###1. 查看仓库 git remote git remote -v ###2. 添加远程仓库 git remote add origin git://github.com/someone/another_project.git 这句话就是把当前目录下的Git库添加到远端,origin为这个库的别名 ###3. 删除远程仓库 git remote rm origin 这句话删除了远端名为origin的库 ###4. 重命名 git remote rename github gh 这句话就是把远端的github这个库重命名为gh ###5. 抓取 git remote fetch origin 从远程仓库抓取数据,更新本地仓库

4. branch

1. 查看本地分支

git branch

2. 查看远端分支

git branch -r

3. 创建分支

git branch myBranch

这句话只创建,不会切换

git checkout -b myBranch

这句话会创建分支并切换到新分支

4. 切换分支

git checkout myBranch

5. 删除分支

git branch -d myBranch

6. 合并分支

git merge myBranch

把某个分支合并到当前分支

7. 创建远程分支(Push)

git push origin myBranch

8. 删除远程分支(Push)

git push origin :heads/myBranch

##4. tag ###1. 查看版本 git tag ###2. 创建版本 git tag myTag ###3. 删除版本 git tag -d myTag

常用命令

  • 获得最新版本
    • git pull从Git上获取最新版本到本地
  • 添加文件
    • git add readme.md把a.c这个文件添加到本地git库中
  • 删除文件
    • git rm a.c把a.c从本地库中删除
  • 提交当前代码
    • git commit -m "附加说明"把当前文件提交到仓库
  • 查看当前状态
    • git status当前仓库的状态
  • 对比修改状态
    • git diff当前仓库被修改的状态
  • 版本号
    • git log查看当前仓库的版本号
    • git log --graph用图形界面查看分支图
  • 撤销修改
    • git checktou -- a.c把a.c里面所有被修改的代码都还原
  • 查看分支
    • git branch查看当前分支
    • git branch -r查看远端分支
  • 切换分支
    • git checkout origin切换到origin分支
  • 合并分支
    • git merge origin把当前分支合并到主分支
  • 删除分支
    • git branch -d origin删除origin分支
  • 推送
    • git push把当前的分支推送到远端
posted @ 2014-07-25 15:55  wisejoker  阅读(232)  评论(0编辑  收藏  举报