git常用指令

<a>github的提交方式
     git status
     (1)git add .--------------------存储到本地
      git add -u
         git commit -m 'message'-------存储时的标记(修改了哪些地方,方便下次查询)
         git pull------------------------下载服务器代码
         git push------------------------上传代码至服务器
  <b>svn服务器的提交方式
   (1)git add .  ------------------存储到本地
        git commit -m 'message'--------存储时的标记(修改了哪些地方,方便下次查询)
        git svn rebase------------------下载服务器代码
        git svn dcommit-----------------上传代码至服务器
   <c>其他相关的git命令
(1)git branch-------------------查看当前属于哪个分支
    1、只有冲突存在时才会修改分支——改为冲突再git add .
    2、git rebase –-continue-------------------自动合并
    3、git checkout –b svn 新建分支名----------新建分支存储现有文件
    4、git branch-------------------------------查看在哪个分支下
    5、git checkout master----------------------将其放到master分支下
    6、git merge-------------------------------整合分支
    7、git branch -d 分支名----------------------删除分支
(2)git checkout + 上传的commit编号-----------将本地代码恢复到此状态
(3)git log------------------------------------查看本地git上传日志
(4)git log -p app/controllers/grids_controller.rb----查看某个文件的修改历史
(5)git checkout d0eb6ef3afe8a377943d3cf6f1e9c320c18f6f32
     app/controllers/charts_controller.rb-----------返回到这个版本的文件(重现错误)
(6)git diff + commit编号--------------------------查询不同代码


需要熟记的github常用命令
总结一下ubuntu下github常用的命令,设置部分跳过,假设repository的名字叫hello-world:
 
1.创建一个新的repository:
 
先在github上创建并写好相关名字,描述。
 
$cd ~/hello-world //到hello-world目录
 
$git init //初始化
 
$git add . //把所有文件加入到索引(不想把所有文件加入,可以用gitignore或add 具体文件)
 
$git commit //提交到本地仓库,然后会填写更新日志( -m “更新日志”也可)
 
$git remote add origin git@github.com:WadeLeng/hello-world.git //增加到remote
 
$git push origin master //push到github上
 
2.更新项目(新加了文件):
 
$cd ~/hello-world
 
$git add . //这样可以自动判断新加了哪些文件,或者手动加入文件名字
 
$git commit //提交到本地仓库
 
$git push origin master //不是新创建的,不用再add 到remote上了
 
3.更新项目(没新加文件,只有删除或者修改文件):
 
$cd ~/hello-world
 
$git commit -a //记录删除或修改了哪些文件
 
$git push origin master //提交到github
 
4.忽略一些文件,比如*.o等:
 
$cd ~/hello-world
 
$vim .gitignore //把文件类型加入到.gitignore中,保存
 
然后就可以git add . 能自动过滤这种文件
 
5.clone代码到本地:
 
$git clone git@github.com:WadeLeng/hello-world.git
 
假如本地已经存在了代码,而仓库里有更新,把更改的合并到本地的项目:
 
$git fetch origin //获取远程更新
 
$git merge origin/master //把更新的内容合并到本地分支
 
6.撤销
 
$git reset
 
7.删除
 
$git rm * // 不是用rm
 
//——————————常见错误———————————–
 
1.$ git remote add origin git@github.com:WadeLeng/hello-world.git
 
错误提示:fatal: remote origin already exists.
 
解决办法:$ git remote rm origin
 
然后在执行:$ git remote add origin git@github.com:WadeLeng/hello-world.git 就不会报错误了
 
2. $ git push origin master
 
错误提示:error:failed to push som refs to
 
解决办法:$ git pull origin master //先把远程服务器github上面的文件拉先来,再push 上去

原文地址:https://www.cnblogs.com/nullman/p/6149030.html