git checkout 某些文件,尽管有冲突
我经常发现自己只想签出树中的某些文件,但不能,因为我已经在本地修改了它们,并且不想尝试找出合并的麻烦(我不想合并任何东西 - 我只想要某些文件的 git 版本) 。
那么,如何强制检出这些文件分散在目录结构中的“db-backup*”等内容呢?
例如,
git-parent
- dir1
- db-backup1
- dir2
- db-backupA
谢谢,
r。
I frequently find myself wanting to checkout only certain files in a tree but cant because I have modified them locally and dont want the hassle of trying to figure out merge (I dont want to merge anything - I just want the git version of certain files).
So how can I force a checkout of, for example, "db-backup*" where these files are scattered over a directory structure?
e.g
git-parent
- dir1
- db-backup1
- dir2
- db-backupA
thanks,
r.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有几种可能的解决方案,具体取决于您想要执行的操作
如果您想放弃更改,可以使用
如果您想保存更改供以后使用,但现在不用担心,您可以< strong>隐藏您的更改,然后进行结账:
要恢复您的更改,请使用
git stash pop
(或git stash apply
)。如果您只想查看文件的 Git 版本(也许将其保存在临时文件中,或以其他名称保存),您可以使用
git show
来实现:如果您想签出某个目录或其他地方的文件子集,您可以使用
git archive 如 git-archive 主页的“示例”部分所述:
请注意,它将使用 HEAD(上次提交)中的版本,而不是索引中的版本,尽管通常没有区别。
实现这一点的另一种方法是使用
git checkout-index
的--temp
选项,尽管这可能被认为是黑客行为。华泰
There are a few possible solutions, depending on what you want to do
If you want to discard your changes, you can use
If you want to save your changes for later, but not worry about them for now, you can stash away your changes and then do a checkout:
To recover your changes, use
git stash pop
(orgit stash apply
).If you want to simply view Git version of a file (and perhaps save it in temporary file, or under other name), you can use
git show
for that:If you want to checkout some directory or subset of files in some other place, you can either use
git archive
as described in "Examples" section of git-archive homepage:Note that it would use version from HEAD (last commit), not from the index, though usually there would be no difference.
Another way of achieving that is to use
--temp
option ofgit checkout-index
, though this can be considered hackery.HTH
即使文件有修改,
git checkout
对我来说也能正常工作。您到底收到了什么错误,您想运行什么命令?这可能应该有效:git checkout <filename>
works fine for me even if there are modifications to the file. What exactly are you getting as an error, and what command are you trying to run? This should probably work:对于 Git 2.23+(2019 年 8 月),最佳实践是使用
git Restore< /code>
而不是 令人困惑的
git checkout
命令。与 pathspec 结合使用,将恢复工作树HEAD 内容(即:取消暂存)
With Git 2.23+ (August 2019), the best practice would be to use
git restore
instead of the confusinggit checkout
command.Combined with a pathspec, that would restore the working tree with HEAD content (ie: unstage)