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

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

git checkout -h
  • 1
$ 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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

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

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

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

git checkout  ee25a1a3f9465 config/database.php
  • 1

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

git checkout e2fb85c827d24a460d app/Http/Controllers/Auth
  • 1

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

git reset --hard HEAD^
  • 1

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

git log --pretty=oneline
  • 1

回退:

git reset --hard 版本号
  • 1

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

猜你喜欢

转载自blog.csdn.net/daily886/article/details/80611559