git 常见操作

107 阅读1分钟

回到某次commit

  1. 保留提交记录

    git reset --soft commitId(可通过git log 找到对应的commit)

  2. 丢弃提交记录

    git reset --hard commitId

补丁包使用(patch)

将项目的某次commit 生成一个文件,通过这个文件可将commit 的代码提交到另外一个人的项目里

  1. 打补丁:git format-patch commitId
  2. 使用补丁:git apply 生成的文件名

暂存代码(stash)

解决冲突或不想提交到线上使用,当本地代码和线上代码冲突时,可先将本地代码暂存,拉取线上代码后再取出来

  1. git add .
  2. git commit -m xx
  3. git stash
  4. git pull
  5. git stash pop