git 特殊用法

回退commit

git log

git reset --hard <commit_id>

git push origin HEAD --force

解决合并冲突

git checkout -b conflict_fix
# do some commit conflictly
Auto-merging xxx
CONFLICT (content): Merge conflict in xxx
Automatic merge failed; fix conflicts and then commit the result.
# 解决文件中的
<<<<<<< HEAD
something older
=======
something newer
>>>>>>> feature1
git add 
git commit -m 
git checkout master
git merge conflict_fix
git push

 切换分支还原变化 

git checkout master
git stash
git checkout dev
git stash pop
或者
git stash list
git stash apply stash@{0}

 覆盖commit

git commit --amend #修改旧commit
或者
git rebase -i #覆盖最上边的一个commit
git push --force

 删除远程分支

git push -d mybranch

同步远程分支(删除本地有远程没有的分支)

git remote prune origin

 修改提交消息(包括commit作者)

For example, if your commit history is A-B-C-D-E-F with F as HEAD, and you want to change the author of C and D, then you would...

Specify git rebase -i B (here is an example of what you will see after executing the git rebase -i B command)
if you need to edit A, use git rebase -i --root
change the lines for both C and D from pick to edit
Once the rebase started, it would first pause at C
You would git commit --amend --author="Author Name <email@address.com>"
Then git rebase --continue
It would pause again at D
Then you would git commit --amend --author="Author Name <email@address.com>" again
git rebase --continue
The rebase would complete.
Use git push -f to update your origin with the updated commits.

 清理和回收空间

$ git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch .' --prune-empty --tag-name-filter cat -- --all
$ rm -rf .git/refs/original/

$ git reflog expire --expire=now --all

$ git gc --prune=now

$ git gc --aggressive --prune=now
原文地址:https://www.cnblogs.com/chenminklutz/p/10303177.html