git折腾日志

  • git for windows
https://git-for-windows.github.io/
  • 基本配置

进入git bash后执行

$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"
  •  创建版本库

在需要创建为git的目录下执行

$ git init
  • 添加文件
$ git add FILENAME
  •  为一段修改做注释
$ git commit -m "COMMIT TEXT"
  •  显示当前仓库的状态
$ git status
  • 查看某个文件被修改的信息
$ git diff FILENAME
  • 查看git日志
$ git log
  • 回滚到之前的某个版本
$ git reset --hard HEAD^ #^号的个数表示回滚到上几个   
$ git reset --hard HEAD~100 #回滚到上100个版本
$ git reset --hard COMMIT_ID #回滚到指定 commit id 的版本
  • 查看每一次命令
$ git reflog
  • 删除仓库中某个文件
$ git rm FILENAME
  • 恢复某个被误删的文件(删除了源文件,未在git中删除)
$ git checkout -- FILENAME
  • 从github上clone仓库到本地
$ git clone URLS #URLS为github生成的仓库地址
  • 将clone下来的仓库上传到github
$ git push origin master

连接 Github

生成 ssh keys

$ ssh-keygen -t rsa -C "youremail@example.com"

在 Github 中添加 ~/.ssh/id_rsa.pub

在 本地和Github 中各创建一个仓库,将本地仓库与 Github 上的仓库关联

$ git remote add origin git@URLS #origin为自定义用户名,URLS为Github仓库的链接

 取消关联

$ git remote rm origin

查看关联状态

$ git remote -v

将本地仓库上传到远程仓库

git push username master #username为之前设置的用户名 -f参数用于强制推送
原文地址:https://www.cnblogs.com/xiepingfu/p/7965961.html