Git 常用操作

详细文档可以参考廖雪峰git教程 网址http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

下面记录一些常见操作

本地仓库与远程仓库关联

git remote add origin git@github.com:michaelliao/learngit.git
注意把用户名换成自己的


git add "filename"

git commit -m "提交说明"

git push origin master 意思是提交到远程库master分支

遇到类似与下面的错误

 [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to 'https://git.oschina.net/sulliy/i.git'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')

hint: before pushing again.

可以通过命令 git pull origin master 解决 用来同步远程和本地

如果git pull origin master 报错:refuse to merge unrelated histories

可以用 git pull --allow-unrelated-histories origin master 即可强行合并

下面介绍最想记录的一点 删除远程库文件,即删除远程githup网站上的文件

  使用 git rm 命令即可,有两种选择.

         一种是 git rm --cached "文件路径",不删除物理文件,仅将该文件从缓存中删除;

         一种是 git rm --f "文件路径",不仅将该文件从缓存中删除,还会将物理文件删除(不会回收到垃圾桶)

    假如你有文件不小心commit到了服务器那么你想要删除它,可以使用:

[plain]  view plain copy
  1. git rm -- cached "路径+文件名"  

    接下来:

[plain]  view plain copy
  1. git commit -m "delete file"  

    最后:

[plain]  view plain copy
  1. git push  origin master

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值