JustYeh的前端博客

git常用命令

2019-05-31

git

记录比较常用但是容易忘记的git命令

远程仓库和本地仓库建立关联

git remote add origin `[email protected]:justyeh/www.justyeh.top.git`

强制使用远程仓库覆盖本地

git fetch --all && git reset --hard origin/master && git pull

git checkout远程分支没反应

checkout前先执行fetch更新remote索引, 取回所有分支(branch)的更新

git fetch
git checkout 'remote-branch-name'

分支的操作

#查看远程分支
git branch -r

#查看所有分支
git branch -a

#删除本地分支(不能再当前分支删除自己)
git branch -d branch-name

#删除远程分支
git push origin :remote-branch-name

查看单个文件每次提交的内容差异

git log -p 'file'

查看某次提交修改的内容

git show 'commit_id'

提交所有被修改的文件

git commit -am 'commit message'