git-practice
error: the branch 'xx' is not fully mergedgit merge --abortgit cherry-pick specialhashgit checkout -b new-branch special-hashgit 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 directorygit log -p -p为--patch缩写git log --statgit show special-hashgit show special-hash file-namegit diff --staged或者--cachedgit diffgit diff HEAD,新建的文件没有被追踪,所以是看不到工作目录新建文件和commit的区别git rebase mastercareteenL 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