这个刚开始写博客,就先把自己以前总结的Git的一些语法写上去吧,不说全,还是不少的

来源:互联网 发布:淘宝会员等级怎么刷 编辑:程序博客网 时间:2024/04/29 18:30

Git的一些操作方法

  • mkdir test (创建一个文件夹test)
  • git pwd (显示当前文件的路径)
  • cd test (切换到test文件目录下)
  • touch a.md (创建一个a.md文件)
  • git diff a.md (查看a.md修改了哪些内容)
  • cat a.md (查看a.md文件的内容)
  • git init (初始化一个empty的仓库)
  • git status (查看状态)
  • git add a.md (添加到缓存区)
  • git add * (添加所有)
  • git commit -m firstcommit (提交 -m 提交信息 firstcommit是一个标记)
  • git reset –hard HEAD^ 或者 git reset –hard HEAD~ 回退到上一个版本
    (如果想回退到100个版本,使用git reset –hard HEAD~100 )
  • git log (可以看到所有产生的commit记录)
  • q 退出git log 状态
  • git reflog(查看历史记录)
  • git branch(查看分支情况)
  • git branch a (创建一个名字叫a的分支)
  • git checkout a (切换分支 )
  • git checkout -b a (新建一个分支,并且自动切换到a)
  • git merge (合并分支)
  • git branch -d a (删除a分支)
  • git branch -D a(强行删除)
  • git tag v1.0 (创建当前为1.0的版本)
  • git tag (查询历史的版本记录)
  • git checkout v1.0 (也可以用来查询不同版本的状态)
  • git remote add origin https://github.com/tugenhua0707/testgit (管理一个版本库)
  • git push –u origin master(第一次要用-u 以后不需要)
    (把当前master分支推送到远程库)
  • git push origin master (把本地代码推到远程master分支)
  • git clone https://github.com/tugenhua0707/testgit (从远程库中克隆到本地)
  • git stash (把当前的工作隐藏起来 等以后恢复现场后继续工作)
  • git stash list (查看所有被隐藏的文件列表)
  • git stash apply (恢复被隐藏的文件,但是内容不删除)
  • git stash drop (删除文件)
  • git stash pop (恢复文件的同时 也删除文件)
  • git remote (查看远程库的信息)
  • git remote –v (查看远程库的详细信息)
  • 如果是输出状态,首先Esc退出输入状态,然后Shift+;,再输入q!或wq!(不保存改动,wq!是保存文件的写入修改)退出

SSH

一种网络协议,用于计算机之间的加密登录

生成SSH Key

然后输入ssh-keygen -t rsa 使用rsa算法生成密匙,连续三个回车键,会生成两个文件
1. id_rsa (密匙)
2. id_rsa.pub (公匙)

在Github上添加SSH key

在左上角的设置页面
* 找到SSH and GPG keys
* 点击 New SSH key (把id_rsa.pub)中的内容复制粘贴上去就可以了,title不需要填写
* 然后点击 Add SSH key 就可以了


failed to push some refs to ‘https://github.com/miaorulai/recyleView.git’ hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You maywant to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.

出现错误的主要原因是github中的README.md文件不在本地代码目录中

这个问题的解决方法 是

  • git pull –rebase origin master
  • git push -u origin master

以后再有新的在加,好吧

0 0
原创粉丝点击