git-practice
error: the branch 'xx' is not fully merged
git merge --abort
git cherry-pick specialhash
git checkout -b new-branch special-hash
git rebase --onto master special-hash^
git add -A //stages All
git add . //stages new and modified, without deleted
git add -u //stages modified and deleted, without new
git reset HEAD <file>... //to unstage
git checkout -- <file>... //to discard changes in working directory
git log -p
-p为--patch缩写git log --stat
git show special-hash
git show special-hash file-name
git diff --staged
或者--cachedgit diff
git diff HEAD
,新建的文件没有被追踪,所以是看不到工作目录新建文件和commit的区别git rebase master
careteenL modified
ketingwang modified agin
# 第一次修改
# 第二次修改
利用--amend
参数进行修正
注:并不是修改上一次commit,而是生成新的commit取代上一次commit。
git commit --amend
git reset --hard 目标commit
git reset --hard HEAD^
方式一:
// git rebase -i 目标commit
git rebase -i HEAD^^
// 进入交互页面编辑删除 想丢弃的commit即可
// 然后继续操作
git rebase --continue
方式二:
// git rebase --onto 目标commit 起点commit 终点commit
git rebase --onto HEAD^^ HEAD^ master
场景一:出错的提交在自己的分支
// git rebase -i 目标commit
git rebase -i HEAD^^
// 进入交互页面编辑删除 想丢弃的commit即可
// 然后继续操作
git rebase --continue
//git push origin 当前分支 -f -f为--force简写,不解决冲突强制提交。
git push origin branch1 -f
场景二:出错的提交在master
此时不能像场景一强制提交,因为master分支可能存在同事的push,强制提交会将他们的提交内容抹掉
使用revert将错误撤销 ........
// git revert 目标commit
git revert HEAD^
git add .
git commit -m 'xxx'
git push