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

本文详细介绍了如何使用Git命令进行文件和文件夹的版本回退,包括如何回退到指定版本、如何解决冲突以及如何强制回退。同时,提供了Git checkout命令的详细用法,帮助读者更好地理解和操作Git。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://blog.youkuaiyun.com/zhezhebie/article/details/79420752

https://blog.youkuaiyun.com/zhezhebie/article/category/6882468/1?

git 冲突解决

https://www.cnblogs.com/baby123/p/6588378.html

 

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

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


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

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看到。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值