Skip to main content

Git常用操作

· One min read
  1. 有新代码提交后文件冲突,不能 pull 代码,Git 不能像 SVN 那样自动 Merge,可:
git stash
git pull
git stash pop
  1. 比较两个 commit 之前的修改,生成 patch 文件并 apply 到其它地方:
git diff {较早 commit hash} {较新 commit hash} > MyPatch.diff
git apply MyPatch.diff
  1. 从其它分支提取某一个提交并 apply 到当前分支:
git cherry pick {某次 commit hash}
  1. Reset操作
git reset {mode} {commit}
  1. mode: --hard 放弃本地修改, 重置所有文件状态和修改内容 --mixed 重置所有文件状态, 保留文件内容 --soft 保留本地文件状态和内容
  2. commit: commit hash, HEAD, origin/<branch name>
ClustrMaps