git config [--global] user.name "xxx" # xxx是用户名
git config [--global] user.email "xxx@yyy.zzz" # xxx@yyy.zzz是邮箱
git config --list
git config -e [--global]
git clone git@gitlab.com:xxx/yyy.git
git branch xxx # xxx自定义的分支名
git checkout xxx # xxx自定义的分支名
git checkout -b xxx # xxx自定义的分支名
git branch
git branch -r
git branch -a
git remote update origin --prune # 这里要注意下,如果你的remote branch不是在origin下,按你得把origin换成你的名字
git branch -d xxx # xxx是自定义的本地分支名
git push origin --delete xxx # xxx是要删除的远程分支名
git push origin :xxx # xxx是要删除的远程分支名
git remote [-v]
git status
git add xxx # xxx是修改的文件名
git commit -m "msg"
git diff xxx # xxx是修改的文件名
git diff HEAD -- xxx # xxx是修改的文件名
git rm xxx # xxx是修改的文件名
git mv xxx yyy # xxx是原始文件名,yyy是修改后的文件名
git checkout -- xxx # xxx是修改的文件名,撤销git add前的操作
git reset HEAD xxx # xxx是修改的文件名,撤销git add操作并保留修改内容
git reset --hard commit_id # 先取消git commit操作
git push origin HEAD --force # 再push到远程分支
git stash [save "msg"]
git stash list
git stash apply [stash@{n}] # n是存储区域中的序号,不指定stash,则默认取最顶层的
git stash drop [stash@{n}] # n是存储区域中的序号,不指定stash,则默认取最顶层的
git stash pop
git stash clear
git push -u origin master # 推送到远程master版本库
git push origin xxx:yyy # xxx是本地版本库,yyy是远程版本库
git reset --hard HEAD/HEAD^/HEAD^^/HEAD~100 # HEAD是远程仓库的当前最新版本,HEAD^是上一个版本,以此类推
git log xxx # xxx是文件名
git log -p xxx # xxx是文件名
git log [--graph] [--pretty=oneline]
git show commit_id xxx # xxx是文件名
git reflog
git tag
git tag xxx commit_id # xxx是tag名称
git show xxx # xxx是tag名称
# 普通推送时出现以下报错:
To https://gitlab.xxx.net/xxx/xxx.git
! [rejected] local_xxx -> remote_xxx (non-fast-forward)
error: failed to push some refs to 'https://gitlab.xxx.net/xxx/xxx.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
# 当确认本地版本库修改的内容不会和远程仓库出现冲突时。可以进行强制推送,-f为force,意为:强行、强制。
git push -f origin local_branch:remote_branch
原文:https://www.cnblogs.com/dongshanzhishi/p/9433770.html