自动化运维 --- 1. git 常用指令

一. git 概括

二.常用指令

git init 初始化

git status 查看git的状态

git add 将文件放到缓存区

git commit -m 将缓存区的内容提交到本地仓库

git config --global user.email 'xiaoqiang@oldboyedu.com'设置用户的邮箱

git config --global user.name "saoxiaoqiang" 设置用户的用户名

git config --global --unset user.email  删除用户的邮箱

git config --global --unset user.name 删除用户的用户名

git log 查看当前版本之前提交记录 git reset
--hard hash值 回退到之前某次提交的地方 慎用 git reflog 查看所有的提交记录 git checkout filename 将指定文件回退到最近一次commit的地方,只对工作区做修改,缓存区不变 慎用 git reset HEAD filename 将指定文件从缓存去拉取到工作区,不会覆盖原来的文件

git diff 对比缓存区和工作区的区别 git diff
--cached 对比缓存区和本地仓库的区别 远程: git remote add origin https://github.com/417685417/cw.git 添加别名 git clone https://git...... 克隆 远程文件 git push origin master 将本地的文件上传到远程仓库 git pull origin master 将远程仓库的文件拉取到本地

git pull origin master
将远程仓库的文件 强行拉取 到本地


git stash 创建一个快照 git stash pop 取出快照并删除快照记录 git stash list 查看快照记录 git stash drop name 删除快照 git stash apply name 取出快照

三.常见错误

1.因为线上版本跟本地版本库不一致,本地版本比线上新

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

error: failed to push some refs to 'https://github.com/417685417/cw.git'                                 

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

hint: its remote counterpart. Integrate the remote changes (e.g.                                         

hint: 'git pull ...') before pushing again.                                                              

hint: See the 'Note about fast-forwards' in 'git push --help' for details.  
  解决方法:




` 2.冲突:同时修改了同一个文件的同一个位置,冲突自己解决 `Auto
-merging templates/index.html CONFLICT (content): Merge conflict in templates/index.html Automatic merge failed; fix conflicts and then commit the result.


` 3.因为没有权限 `Logon failed, use ctrl
+c to cancel basic credential prompt. remote: Permission to 417685417/cw.git denied to WuPeiqi. fatal: unable to access 'https://github.com/417685417/cw.git/': The requested URL returned error: 403 `

四.远程仓库

  1.码云

  ①新建仓库

 

   2.创建组织

 

 ③ 

原文地址:https://www.cnblogs.com/sc-1067178406/p/10792540.html