参考学习网址: https://gitee.com/progit/
git分布式版本控制原理:
git安装
- linux:
- Mac:
git的常用命令
add 添加文件内容至索引
bisect 通过二分查找定位引入 bug 的变更
branch 列出、创建或删除分支
checkout 检出一个分支或路径到工作区
clone 克隆一个版本库到一个新目录
commit 记录变更到版本库
diff 显示提交之间、提交和工作区之间等的差异
fetch 从另外一个版本库下载对象和引用
grep 输出和模式匹配的行
init 创建一个空的 Git 版本库或重新初始化一个已存在的版本库
log 显示提交日志
merge 合并两个或更多开发历史
mv 移动或重命名一个文件、目录或符号链接
pull 获取并合并另外的版本库或一个本地分支
push 更新远程引用和相关的对象
rebase 本地提交转移至更新后的上游分支中
reset 重置当前HEAD到指定状态
rm 从工作区和索引中删除文件
show 显示各种类型的对象
status 显示工作区状态
tag 创建、列出、删除或校验一个GPG签名的 tag 对象
所有的文件,在git中都有三种状态:已提交(committed)、已修改(modified)、已暂存(staged)
文件流转的三个区域:git的工作目录、暂存区域以及本地目录
git使用:
1、本地化初始目录: git init
2、克隆远程项目至本地:git clone
3、查看文件状态:git staus
GaofhdeMacBook-Pro:gaofeihong a1234$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test1.txt
new file: test2.txt
new file: test4.txt
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: test1.txt
deleted: test4.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
README
test3.txt
4、添加文件到暂存区域,跟踪文件:git add
5、git rm
6、提交文件到版本库: git commit -m '修改说明'
7、注释重写:git commit --amend -m '注释重写'
git分支管理
1、新建分支:git branch 分支名(如:develop)
2、查看目前分支:git branch / git branch -v (.git文件下HEAD文件记录当前
分支)
GaofhdeMacBook-Pro:gaofeihong a1234$ git branch -v
fix 518619d mastst
fix2 666718a 在testing分支修改test1.txt的修改
* master 0233158 Merge branch 'testing'
testing 666718a 在testing分支修改test1.txt的修改
v 0233158 Merge branch 'testing
3、切换分支:git checkout 分支名
4、删除分支:git branch -d 分支名(不能删除当前分支)
其他不能删除的情况:包含未合并的内容,在删除分支前,建议先合并
GaofhdeMacBook-Pro:gaofeihong a1234$ git branch -d develop
Deleted branch develop (was fee676f).
5、git checkout -b 新分支名:从当前分支拉出新分支,并且切换到新分支
6、git merge 分支名 合并分支
git merge --no--ff 合并分支
分支冲突合并:合并的文件有重复
版本穿梭
在多个commit之间回退、前进
回退到上一次版本:git reset --hard HEAD^
回退到两个版本: git reset --hard HEAD^^
回退到前n个版本:git reset --hard HEAD~n
git log
查看日志提交记录:git log
查看前几条日志提交记录:git log n
查看图形化日志提交:git log --graph
查看日志记录:git reflog
远程分支
1、git remote