Git基本的顺序操作
- git init 初始化本地仓库
git add . 把本地仓库所有文件添加值缓冲区
git commit -m “第一次提交” 加备注
git remote add origin (https://github.com/…)为github地址 绑定远程仓库中的哪个项目
git push -u origin master 上传至绑定的远程仓库中
git pull origin master 拉取远程仓库
git pull --rebase origin master
git remote rm origin 取消远程仓库的绑定
git常用的命令集
git常用的命令集
$ clear 清屏
$ mkdir *** 创建***文件夹
$ touch 创建文件可带文件后缀 如 file.txt
$ pwd 查看当前URL$ ls -ah 查看该目录集文件
$ git init 在当前目录下创建Git仓库
$ git add *** 将***提交到暂存区
$ git commit -m "" 从暂存区提交到当前分支 并为本次提交增加介绍内容
[我们创建Git版本库时,Git自动为我们创建了唯一一个master分支, 所以,现在,git
commit就是往master分支上提交更改。]$ ssh-keygen -t rsa -C "[email protected]" 创建SSH Key
$ git status 了解仓库当前的状态
$ git diff 看具体修改了什么内容
$ git log 显示从最近到最远的提交日志
$ git reset --hard head^ 回退到上一(*)版本(可多个)
$ git reset --hard **** 回退到版本****
扫描二维码关注公众号,回复: 12884460 查看本文章$ git checkout – *** 将***的暂存区内容清除
$ git reset head *** 退回到最新版本–即上一版本
$ git remote add origin ***** 绑定远程仓库
$ git push -u origin master 首次将本地库上传到远程GitHub仓中
$ git clone ***** 克隆一个本地库
git push origin master 非首次推送最新修改可省略 -u
$ git remote rm origin 移除远程仓库的绑定
$ git checkout -b *** 转换到一个分支***如果没有就创建一个新的 [ git checkout
命令加上 -b 参数表示创建并切换,相当于以下两条命令:
$ git branch *** //创建一个 *** 分支
$ git checkout *** //转换到 *** 分支
Switched to branch ‘***’]$ git branch 命令会列出所有分支,当前分支前面会标一个 * 号
$ git merge *** 合并某分支到当前分支
$ git branch -d *** 删除***分支
Git鼓励大量使用分支
- 查看分支:
git branch
- 创建分支:
git branch <name>
- 切换分支:
git checkout <name>
- 创建+切换分支:
git checkout -b <name>
- 合并某分支到当前分支:
git merge <name>
- 删除分支:
git branch -d <name>
Git忽略大小写设置
- 关闭git忽略大小写配置
git config core.ignorecase false
Git查看工作区内的某个文件
比如查看我项目中C:\Users\Administrator\Desktop\ARSmallAnimal\Assets_Scripts文件夹下面的ScenePath.cs文件
首先进入进入到被访问的文件的目录
之后输入
cat ScenePath.cs
就可查看文件内容
Git修改工作区中的某个文件
比如我工作区中有 dic.txt 这个文件(首先要进入该文件所在的文件夹内)
cat dic.txt 可以查看文件
vi dic.txt 可以编辑文件
按esc 退出编辑
按esc之后 在输入 :wq 按回车退出编辑回到命令行
Git版本回退
- 查看提交记录
git log
- 查看commit_id
git reflog
- 版本回退一次
git reset --hard HEAD^
- 版本回退两次
git reset --hard HEAD^^
- 版本恢复(commit_id是指定恢复或回退到的那个版本)
git reset --hard commit_id
Git 错误锦集
1. git add . 的时候文件报错
添加文件到暂存缓冲区 git add .
报错误
warning: LF will be replaced by CRLF in title.md. The file will have its original line endings in your working directory
错误解释
意思大概是:LF(换行,Line Feed)将会被CRLF(回车换行,CarriageReturn)替代。
该文件将在工作目录中具有其原始行尾。
解决办法
$ rm -rf .git//删除 .git
$ git config --global core.autocrlf false //禁用自动转换
然后重新执行
$ git init
$ git add .
2.git push -u origin master 文件时出错误
报错内容
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘https://github.com/YaoGaoShang/GitDemo.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.
出错原因
因为我远程仓库中有一个README.md文件,本地仓库中没有所以先要被远程仓库中的文件拉去到本地仓库
解决方案
git pull --rebase origin master
然后操作
git push origin master
. 参考链接
- https://git-scm.com/downloads Git下载地址
- https://blog.csdn.net/gpwner/article/details/52829187 Git安装
- https://www.liaoxuefeng.com/wiki/896043488029600 Git使用教程
- https://gitee.com/help/articles/4192#article-header0 码云Gitee
- https://blog.csdn.net/Gpwner/article/details/53140016 Git教程之一个团队如何在github上协作开发