其他分享
首页 > 其他分享> > 关于git reset (回退)

关于git reset (回退)

作者:互联网

关于git reset (回退)

  1. 未提交

    1. 在工作区做了修改,但未执行git add. 到暂存区

    2. 已经git add .提交到暂存区,但未执行commit 提交到本地仓库

      这时候回退用git reset --hard 将删除所有痕迹

      用git reset --soft 回退到暂存区并保留修改

  2. 已提交未推送 (已经add,commit 但未push 到远程仓库)

  3. 上个版本回退,执行git reset hard commit_id(commit_id是倒数第二个)

  4. 回退到指定版本 ,git reset --hard <commit_id>

  5. 已推送

  6. git reset --hard commit_id

  7. git push -f

已经推送到远程仓库的,git reset 回退之后,千万别git pull ,否则之前的git reset就白做了,这个时候本地也是没有修改的文件,如果git push 将会报下面的错误,这个时候要强制推送 git push -f

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

标签:reset,git,--,push,回退,commit
来源: https://www.cnblogs.com/wszzj/p/16177089.html