Git
Git 常用命令
git --version 查看 git 版本
git config --global user.name 用户名 设置用户签名
git config --global user.email 邮箱 设置用户签名
git init 初始化本地库
dell@DESKTOP-VSDN0Q2 MINGW64 /d/Git-Space/SH0720
$ git init
Initialized empty Git repository in D:/Git-Space/SH0720/.git/
dell@DESKTOP-VSDN0Q2 MINGW64 /d/Git-Space/SH0720 (master)
$ ll -a
total 4
drwxr-xr-x 1 dell 197121 0 May 3 12:27 ./
drwxr-xr-x 1 dell 197121 0 May 3 12:27 …/
drwxr-xr-x 1 dell 197121 0 May 3 12:27 .git/
vim hello.txt 新建文件
- i 编辑
- esc
- yy 复制
- p 粘贴
- :wq 保存
- ll 当前目录下查看
- cat 查看文件内容
- tail -n 1查看文件末尾第一行内容
git status 查看本地库状态
git add 文件名 添加到暂存区
git commit -m “日志信息” 文件名 提交到本地库
git reflog 查看历史记录
git reset --hard 版本号 版本穿梭
Git 分支
git branch 分支名 创建分支
git branch -v 查看分支
git checkout 分支名 切换分支
git merge 分支名 把指定的分支合并到当前分支上
冲突合并
冲突产生的表现:后面状态为 MERGING
dell@DESKTOP-VSDN0Q2 MINGW64 /d/Git-Space/SH0720(master|MERGING)
冲突产生的原因:
合并分支时,两个分支在同一个文件的同一个位置有两套完全不同的修改。Git 无法替
我们决定使用哪一个。必须人为决定新代码内容。
解决: 手动解决
步骤:
1)编辑有冲突的文件,删除特殊符号,决定要使用的内容
特殊符号:<<<<<<< HEAD 当前分支的代码 ======= 合并过来的代码 >>>>>>> hot-fix
hello git! hello atguigu! 2222222222222
hello git! hello atguigu! 3333333333333
hello git! hello atguigu!hello git! hello atguigu!
hello git! hello atguigu!
hello git! hello atguigu!
hello git! hello atguigu!
hello git! hello atguigu!
hello git! hello atguigu!
hello git! hello atguigu!
hello git! hello atguigu!
hello git! hello atguigu!
hello git! hello atguigu!
hello git! hello atguigu!
hello git! hello atguigu! master test
hello git! hello atguigu! hot-fix test
2)添加到暂存区
Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master|MERGING)
$ git add hello.txt
3)执行提交(注意:此时使用 git commit 命令时不能带文件名)
Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master|MERGING)
$ git commit -m "merge hot-fix"
[master 69ff88d] merge hot-fix
–发现后面 MERGING 消失,变为正常
Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)
$
GitHub
远程仓库操作
git remote -v 查看当前所有远程地址别名
git remote add 别名 远程地址 起别名
git push 别名 分支 推送本地分支上的内容到远程仓库
git clone 远程地址 将远程仓库的内容克隆到本地
git pull 远程库地址别名 远程分支名 将远程仓库对于分支最新内容拉下来后与当前本地分支直接合并(拉取)