git管理的是修改内容,分支的策略:
master非常稳定,仅用来发布新版本
dev开发分支,组员以dev为基础新建自己的分支,合并
git三个区域:
工作区:开放修改代码
历史区:保存各个版本的区域
暂存区:GIT根目录下 .git index 文件中,保存所有的代码提交记录
add操作就是讲记录保存到暂存区,此时head依然指向之前的内容,通过commit提交,head指向最新内容
远程仓库:
git remote add origin git@github.com:Mxinga/springcloud.git添加远程仓
git clone git@github.com:Mxinga/springcloud.git 克隆,默认master
git fetch origin branchname #远程仓库新建分支,fetch拉取
*命令:
git init:设置当前命令为git代码仓库
git clone:从服务器clone工程,创建代码仓库
git log 查看刚才提交的信息
git shortlog 将开发者操作按照姓名分组
git status:查看仓库状态:哪些文件被修改、哪些内容需要add和commit
git add 文件名:添加文件到仓库
git commit -m '这里是注释'
git commit -amend -m '追加注释,将上次的覆盖掉'
//已写入缓存与已修改但尚未写入缓存的改动的区别
git diff filename 显示文件的变化
git diff head 上次提交节点的差别
git diff --stat 显示摘要
回退、删除:
git checkout -b 本地分支名 origin/远程分支名
git checkout filename:将未add的修改还原,将版本库中文件替换当前文件内容
git checkout -filename: 将add提价的内容全回退掉
git checkout commitId -b localnewbranchName//根据commitId常见commit之前的本地分支
git reset --hard filename:文件从暂存区回退到工作区
git reset --hard HEAD~1 回退1个版本
git reset --hard HEAD~5 回退5个版本
git reset --hard commitid 根据reflog获取commitid,回撤到指定的版本
git rm filename 暂存区上操作 删除
git rm -f filename 强制删除 -r * #递归删除
git rm --cached filename 仅从跟踪清单中删除
git checkout -b dev origin/dev //获取远程dev分支
git clean -d -fx 删除没有add的文件
暂存:
git stash 暂存当前修改
git stash list 查看当前暂存的内容
git stash apply/pop 内容恢复,后者删除记录,前置通git stash drop 删除暂存记录
提交、拉取:
git push <远程主机名> <本地分支名>:<远程分支名> 若省略远程分支,代表将本地当前分支推送到远端对应分支
git push origin HEAD:远程新branchName
git push -u origin master 将本地master分支提交到远程master分支,并关联
git push origin dev 将dev推送到远程仓库
git push origin master //推送到远端的master
git push origin dev //推送到远端的dev
git pull -rebase 远程拉取最新修改
分支:
merge 和 rebase ,rebase操作会合并时间线
git checkout -b branchname #创建新分支并切回到该分支下
git branch #-r显示所有远程分支 -a显示所有本地分支和远程分支
git branch -d branchname 删除分支,-D强行删除分支
git remote origin #查看远程分支
git remote -v origin #查看详细信息
git merge branchname #分支commit后,切刀master上在master上合并
标签tag:
git tag version1.0
git tag version2.0 commitID 在commitID点上打tag
git push origin -tags 推送all标签到远程仓库
git tag查看tag
git tag -a tagname -m 'tag note' -a tag名字,-m 注释文字
git show tagname 显示详细信息
git tag -d tagname 删除tag
git push origin :refs/tags/<tagname> 可删除一个远程标签
重命名:git mv oldname newname
gitignore:忽略gitignore文件中的文件
https://www.jianshu.com/p/45c1a64cf1ff
http://www.cnblogs.com/caoyi/p/9843142.html
http://www.runoob.com/git/git-basic-operations.html
https://www.cnblogs.com/jason-dong/p/8848350.html
https://blog.csdn.net/feather_wch/article/details/78657362