美文网首页
Git操作记录

Git操作记录

作者: 请回答_ | 来源:发表于2020-04-25 01:50 被阅读0次

Git的使用

常用命令

  1. 创建仓库
/*
先在本地某一个位置创建一个文件夹作为你的仓库目录
然后进入该目录,使用init命令即可完成创建
*/
$ mkdir gitfolder   
$ cd gitfolder
$ git init
  1. 添加命令
$ git add filename //添加指定文件
$ git config/*     //config 目录下及子目录下所有文件
$ git home/*.php   //home 目录下的所有.php 文件
$ git add 文件夹名
$ git add --all    //添加所有文件
  1. 提交命令
$ git commit -m "add new file"
  1. 查看状态
$ git status
git status
  1. 查看修改
$git diff filename
  1. 查看日志
$ git log
  1. 回退
    Git 在内部有个指向当前版本的 HEAD 指针
$ git reset --hard 1094a
$ git reset --hard HEAD^
  1. 查看命令历史
$ git reflog
  1. 删除文件、恢复文件
$ rm filename
$ git rm filename
$ git commit -m "commit后从仓库中完成删除"

$ rm filename
$ git checkout -- filename //从版本库中恢复

GitHub远程仓库

  1. 生成SSH key
ssh-keygen -t rsa -C "youremail@example.com"
ssh-key

然后将那一串key添加到GitHub账户的ssh key中

  1. 添加远程仓库
$ git remote add origin git@github.com:accountname/project.git

把本地仓库和远程仓库进行关联
这里遇到的问题:'fatal:remote origin already exists'
解决方法:

$ git remote rm origin
$ git remote add origin git@github.com:accountname/project.git
  1. 推送
$ git push -u origin master
  1. fetch/merge
error: failed to push some refs to 'https://github.com/GDDXZ/RobotDenso.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 may want 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.

解决方法:

  • 强制推送
$ git push -f

可以提交,会将 remote 上第一个人的改动冲掉,比较暴力,不太好。

  • 正常解决
git fetch origin
git merge origin/master 

和本地分支合并,之后再 push。

未完待续...

相关文章

  • 小众GIT

    1、git reflog: 操作记录,找回reset等误操作 2、git rebase --todo 3、git ...

  • GIT-Reflog

    1、git reflog : 查看操作记录 2、撤销某次记录 git reset --soft HEAD@{1} ...

  • log 和 reflog

    git log是查看commit的历史记录。 git reflog是查看所有git操作的历史记录。

  • Git

    Git Git 起步 Git 基础 直接记录快照,而非差异记录 近乎所有操作都是本地执行 时刻保持数据完整性 多数...

  • git 操作记录

    git 删除远程分支 首先查看项目的远程分支 git branch -aimage.png remotes/ori...

  • Git 操作记录

    git commit -am "" 这里 -am 在初始化提交文件时不能这样用 git撤销操作 git comm...

  • git操作记录

    ///文件添加和提交 gitaddfile gitcommit-m"备注" ///查看修改 gitstatus g...

  • git操作记录

    branchName = 要操作的分支名commit id = 使用git log命令查看的版本号 查看全部分支g...

  • Git操作记录

    Git的使用常用命令GitHub远程仓库 Git的使用 常用命令 创建仓库 添加命令 提交命令 查看状态 查看修改...

  • Git操作记录

    本文目录 一台电脑配置多个git账号 git常用的操作命令 使用git命令合并多条commit记录 使用git命令...

网友评论

      本文标题:Git操作记录

      本文链接:https://www.haomeiwen.com/subject/yowcwhtx.html