0
点赞
收藏
分享

微信扫一扫

git回退某一个版本的某个文件

需求是有个文件需要退回到某个指定版本的状态,直接上命令
查看帮助说明:

git checkout -h
$ git checkout -h
usage: git checkout [<options>] <branch>
or: git checkout [<options>] [<branch>] -- <file>...

-q, --quiet suppress progress reporting
-b <branch> create and checkout a new branch
-B <branch> create/reset and checkout a branch
-l create reflog for new branch
--detach detach HEAD at named commit
-t, --track set upstream info for new branch
--orphan <new-branch>
new unparented branch
-2, --ours checkout our version for unmerged files
-3, --theirs checkout their version for unmerged files
-f, --force force checkout (throw away local modifications)
-m, --merge perform a 3-way merge with the new branch
--overwrite-ignore update ignored files (default)
--conflict <style> conflict style (merge or diff3)
-p, --patch select hunks interactively
--ignore-skip-worktree-bits
do not limit pathspecs to sparse entries only
--ignore-other-worktrees
do not check if another worktree is holding the given ref
--progress force progress reporting

一看就知道要用哪个命令:

git checkout [<options>] [<branch>] -- <file>...

那么执行的时候就是这个样子:

git checkout  ee25a1a3f9465 config/database.php

如果要回退整个文件夹到某个版本呢?

git checkout e2fb85c827d24a460d app/Http/Controllers/Auth

git强制回退到上一个版本:

git reset --hard HEAD^

git回退到指定版本:
查看log历史一行一条:

git log --pretty=oneline

回退:

git reset --hard 版本号

注意:这个命令是不会保留指定的那个版本到现在本地的修改的,去掉–hard参数,就可以保留修改,执行完之后可以git status看到。

​​http://gitbook.liuhui998.com/index.html​​


举报

相关推荐

0 条评论