Git签出修订版本,但不删除不受影响的文件 [英] Git checkout a revision without deleting unaffected files
问题描述
我想恢复到以前的版本而不删除文件,对此的直观表示为:
I want to revert to a previous revision without deleting files, a visual representation of this would be:
3个文件;
myfile
mysecondfile
mythirdfile
现在,这是当前的 origin/master
和我的工作副本.
Now this is currently origin/master
and my working copy.
我想做的是还原到以前的版本,可以说 DEADBEEF
,
What I want to do is revert to a previous revision, lets say DEADBEEF
,
DEADBEEF
修订版只有一个文件;
DEADBEEF
revision only has one file;
myfile
我想做的是用以前的版本覆盖本地的 myfile
,而不会删除 mysecondfile
或 mythirdfile
.
What I want to do is overwrite my local myfile
with the previous revision without deleting mysecondfile
or mythirdfile
.
推荐答案
解决方案优先
如果您有可能使用 xargs
命令行命令,这很容易.
Solution first
If you have the possibility to use the xargs
command line command that is an easy task.
$ git ls-tree --name-only -r <tree-ish> . | xargs git checkout <tree-ish> --
使用命令的分解
-
git ls-tree
将会列出树对象的内容
这意味着它将显示特定提交时存储库中存在的所有文件-
-仅名称
会将输出限制为文件的路径(相对,使用-full-name
作为绝对路径) -
-r
将递归显示所有文件 git ls-tree
will list the content of a tree object
This means it will show all the files that were present in the repository at a certain commit--name-only
will restrict the output to the (relative, use--full-name
for absolute paths) path of the files-r
will show all files recursively
要查看自
< tree-ish>
以来所做的更改,请使用:To view the changes that you did since
<tree-ish>
use:$ git diff --staged -R
如果在不使用
-R
的情况下使用该命令,您将看到更改,就好像您将所有内容从更改为旧状态一样.If the command is used without
-R
you would see the changes as if you changed everything to the old state.这篇关于Git签出修订版本,但不删除不受影响的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
Breakdown of commands used
-