知识点
.gitignore 是 Git 仓库中的一个特殊的文本文件,它里面记录了你不希望提交到仓库的目录和文件的名称或类型
.git 目录,就是你的本地仓库(Local Repository),你的所有版本信息都会存在这里
.git 所在的这个根目录,称为 Git 的工作目录(Working Directory),它保存了你当前从仓库中签出(checkout)的内容
untracked:文件目前属于 “untracked” 状态,它的意思是 Git 仓库对它没有进行任何记录,你在提交的时候不会把它提交上去,查看提交历史也不会看到它。总之,对于 Git 仓库来说,它是不存在的。
store:文件改动部分被存放在暂存区
命令
git clone url : 将远程仓库下载到本地中
git status : 查看工作目录当前状态的指令
git add filename : 将新文件由未跟踪状态变为已暂存状态,把改动的内容放进暂存区
git add . : 把工作目录下的所有改动全部放进暂存区
git commit : 将暂存区的内容提交到本地仓库
git log : 列出提交历史
git log -p : 查看每个commit的改动细节
git log --stat : 查看每个commit大致改动
git show : 查看当前commit改动细节
git show commit引用或SHA-1码 : 查看某个commit的改动细节
git show commit引用或SHA-1码 filename : 查看指定commit的指定文件的改动细节
git diff --staged/--cached : 显示暂存区和上一条提交之间的不同
git diff : 显示工作目录和暂存区之间的不同
git diff HEAD : 显示工作目录和上一条提交之间的不同,它是上面这二者的内容相加
// 提交修改后的内容
git add filename
git commit
// 推送到远程仓库
git push
// 从远程仓库更新到本地仓库
git pull
git branch branchname : 在当前commit处创建一个branch
git checkout branchname : 将HEAD指向指定的branch
git checkout -b branchname : 以上两步操作的合并,创建并签出
git branch -d branchname : 删除branch
git branch -D branchname : 删除未完成的branch
git push origin branchname : 将该branch的commit推送到远程仓库
git push origin -d branchname : 删除远程仓库的branch
git merge branchname : 将该branch指向的commit和当前commit合并到一起
git merge --abort : 取消merge
git rebase commit引用或SHA-1码 : 将当前HEAD指向的branch的commit 序列的基础点改到目标commit后
git commit --amend : 该commit不接在当前commit后面,而是替换掉当前commit,可用于修复当前提交的错误
git reset --hard HEAD^ : 撤销当前commit,回退到前一个commit
git push origin branchname -f : 忽略冲突,强制push
git stash -u : 将当前工作目录的全部改动保存到另外一个地方并清空工作目录的改动
git stash pop : 将之前的另存储的改动放回工作目录
常见操作流程
简单的push操作:
将自己的代码push到远程仓库前,先进行pull操作,防止产生冲突,在进行push操作
git add filename
git commit
git pull
git push
push两个branch
git push
git checkout branch1
git push origin branch1
执行merge操作后的特殊情况
1、合并的branch产生冲突,对文件的同一处做了不同的修改
解决冲突:打开文件进行修改,人为保留一处修改
提交:git add filename,git commit
2、HEAD 领先于目标 commit:Git 什么也不做,空操作;
3、HEAD 落后于目标 commit:fast-forward(快速前移)
团队开发工作流:Feature Branching
1、任何新的功能(feature)或 bug 修复全都新建一个 branch 来写;
2、branch 写完后,合并到 master,然后删掉这个 branch。
待续。。。
参考书:
https://juejin.im/book/6844733697996881928