Loading... ## git reset 回滚 ```bash use git reflog to look version number git reset --soft 版本号 # cancel this time commit , but this time edit in workspace and add in staging area(cache) still exit. git reset --mixed 版本号 # cancel this time commit and the one add in staging area(cache) , only keep the one you edited in workspace git reset --hard 版本号 # directly go to last commit one ``` ## git branch ```bash git branch -v # list all branchs git branch branch_name # create a branch called name git branch -D branch_name # delete one branch git checkout branch_name # switch to the branch git merge branch_name # merge branch_name and your curennt anch(usually master) git merge --abort # give up this merge ``` **Specially** if you edited it in the branch and switch to master without commit in the branch, the content what you edited in branch will also apply in your master branch. **So you must commit your edition in your branch before you switch to the master **!! ## git diff ```bash git diff HEAD # 查看工作区与 HEAD 指向(default the last commit at present)的对比 git diff filename # 查看工作区和暂存区单个文件的对比 git diff # 查看工作区和暂存区所有文件的对比 ``` ## git basic ```bash git add # . or filename # submit all file or one file to staging area(cache) git commit -m "remark" # commit the file in staging area(cache) with remark , remark also could be saeen by 下面的命令 git reflog # list all change in file with git git restore filename # if you have already edited the file in workspace, but decide to ga back to the no-edited one use it , Go back to before the modification.将不在暂存区的文件撤销更改,因为是用暂存区的文件覆盖工作区,所以不能睡add完了再restore,那样没有作用 git restore --staged filename # 将缓存区的此文件更换为上一次commit的此文件 , 配合git restore使用,实现恢复误删文件 (不可以在分支中check master的区,需要更新分支中的文件可以merge主区) git checkout # . or filename # 恢复暂存区的指定文件到工作区 git checkout HEAD git checkout HEAD -- filename # 回滚到最近的一次提交 git checkout HEAD^ # 回滚到最近一次提交的上一个版本 (^就是再退一次) git rm filename # 删除工作区,缓存区的文件,同时rm本地此文件 如果误删 1.可以先使用git restore --staged <filename> 用master上次commit的filename的状态来恢复 staged(暂存区)中的filename文件; 然后再使用git restore <filename>通过staged中filename上次的状态来恢复工作区中的filename; 2.git reset 回滚 3.git pull玄学错误 ``` ## git remote ```bash git clone https/ssh # to clone all files in github projects git pull https:/ssh branch_name # pull files to complement local file git push https:/ssh branch_name # push local commit files to remote database git remote -v # 查看当前所有远程地址别名 git remote add 别名 远程地址 # 起别名 ``` ## git brance name standard - 开发人员每天都需要拉取/提交最新的代码到 **「develop 分支」**; - 开发人员开发完毕,开始 **「集成测试」**,测试无误后提交到 **「test 分支」**并发布到测试环境,交由测试人员测试; - 测试环境通过后,发布到 **「release 分支」** 上,进行预发环境测试; - 预发环境通过后,发布到 **「master 分支」**上并打上标签(tag); - 如果线上分支出了 bug ,这时候相关开发者应该基于预发布分支(**「没有预发环境,就使用 master 分支」**),新建一个 **「bug 分支」**用来临时解决 bug ,处理完后申请合并到 预发布 分支。这样做的好处就是:不会影响正在开发中的功能。 最后修改:2022 年 10 月 09 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏