git命令集合
单纯为了帮助记录项目中常用的git命令,方便快速找到使用。毕竟也不是能永久记忆所有命令,网络上搜索命令的结果也是鱼龙混杂。
1.单文件更新
git fetch
git checkout origin/master [branch] [/url/file.name]
// git fetch 报错
git: 'credential-wincred' is not a git command. See 'git --help'.
解决办法:
git config --unset-all credential.helper
git config --global credential.helper osxkeychain
原因:系统不匹配,credential 为Windows系统使用,macos系统使用就会报错
2.撤销提交
git log
// 修改head指针
git reset --hard/soft [commit]
git push -f
// 撤销本地最近一次提交
git reset HEAD~
3.撤销之前的撤销
git reflog
// 修改head指针
git reset --hard/soft [commit]
git push -f
4.单次提交合并
git log
git cherry-pick [commit]
git cherry-pick [commitA]...[commitB]
git cherry-pick [commitA]^...[commitB]
git cherry-pick --skip/continue
// merge-commit 1-接受变动的分支;2-变动来源的分支
git cherry-pick -m 1 [commit]
// 只更新工作区和暂存区,不产生新的提交
git cherry-pick -n [commit]
5.tag操作
git tag -l
git tag -a [name] -m "[detail]"
git push origin [name]
git tag -d [name]
git push origin --delete [name]
// 查看某tag的代码
git checkout [tag_name]
6.不小心删除了远程仓库分支
// 不要慌,本地仓库里还有就可以再拯救一下
git push origin [branch name] --force
7.从某次提交创建分支
git checkout -b [branch name] [commit]
// 从本地新建分支后同步到远程仓库
git push origin [branch name]
8.批量操作本地分支
// 删除除了master分支以外的其他所有本地分支,master属于保护分支
git checkout master
git branch | grep -v 'master' | xargs git branch -D
// 从远程同步所有远程分支
git remote update origin --prune
// 删除某个本地分支
git branch -D [branchName]
9.放弃当前merge
// 在合并有冲突的情况下放弃合并
git merge --abort
1.
// 1
git