开发过程中必用的git指令!
都是开发中常用的指令,如果你喜欢用git的一些插件 工具来代替的话 就不用看了~
初始化相关:
git init 初始化文件夹为git代码库
git init projectName 新建一个projectName文件夹并初始化为git代码库
git clone 有权限下可以下载完整的包括记录、分支的文件
git config --global user.name "liangren" 将全局git 用户名改为liangren
git config --global user.email "liangren@xxx.com" 将全局git 邮箱改为liangren@xxx.com
查看比较记录相关:
git show 查看最新的提交记录
git show commitid 查看某个commitId下的记录

git show commitId fileName 查看某次commit中具体某个文件的修改
git diff 比较当前文件和最新一次pull下来文件的差异
git diff fileName 比较当前文件和最新一次pull下来文件的差异
git diff commitId1 commitId2 比较两次提交之间的差异
git log 查看提交历史记录
提交记录相关:
git checkout branch 切换分支
git chekout . (偷懒捷径,一次性把当前所有的更改都丢弃掉)
git pull 拉取最新代码
git add . 将工作文件修改提交到本地暂存区
git commit -m "备注" 提交本次记录
git push 推送到远程仓库
stash相关:
git stash 将当前的修改挪到暂存区(注意新建的文件不会,始终存在)
git stash pop 从暂存区中取出最近一次添加到stash里的内容
git reset --hard 撤销当前的git stash pop 操作(有时候误操作)
git stash show 查看stash中最近一次修改的内容(git stash show stash@{0} stash@{0}为指定查看的版本 )
git stash list 查看stash的list记录
git stash clear 一次清空所有的stashlist
git stash drop stash@{0} 删除stash 队列中的一个
场景(面试题)
1、如何创建本地与远程仓库的关联
2、如何合并远程两个分支的代码
3、本地commit后但是没有push,想要撤回commit
4、如何撤销远程仓库的提交

浙公网安备 33010602011771号