关于git reset (回退)
作者:互联网
关于git reset (回退)
-
未提交
-
在工作区做了修改,但未执行git add. 到暂存区
-
已经git add .提交到暂存区,但未执行commit 提交到本地仓库
这时候回退用git reset --hard 将删除所有痕迹
用git reset --soft 回退到暂存区并保留修改
-
-
已提交未推送 (已经add,commit 但未push 到远程仓库)
-
上个版本回退,执行git reset hard commit_id(commit_id是倒数第二个)
-
回退到指定版本 ,git reset --hard <commit_id>
-
已推送
-
git reset --hard commit_id
-
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