简体   繁体   English

GIT 我想取消我的结帐并返回未提交的更改? (我可以这样做吗?)

[英]GIT I want to cancel my checkout and get not committed changes back ! (Can I do that ?)

I have done commit.我已经提交了。 Next I made some changes to a file.接下来,我对文件进行了一些更改。 Then I run the command checkout for only one file.然后我只对一个文件运行命令 checkout。 Which looks like this:看起来像这样:

git checkout HEAD^ filename.php

That did not help me at all.那根本没有帮助我。 So I would like to cancel my checkout.所以我想取消我的结帐。 THE QUESTION IS: Can I go back to not only last committed but also to changes made after (not committed)?问题是:我可以 go 不仅回到上次提交,而且还回到之后(未提交)所做的更改?

Thanks for your help: :* Love You all :)感谢您的帮助::*爱你们所有人:)

PS: I got the answer in comments bellow. PS:我在下面的评论中得到了答案。 To save you time guys.为了节省你们的时间。 The answer was NO: :(答案是否定的::(

The modern command (since Git 2.23, Q3 2019) would be git restore :现代命令(自 Git 2.23, Q3 2019)将是git restore

git restore -- filename.php

It would restore the file content from, by default, HEAD.默认情况下,它将从 HEAD 恢复文件内容。

But it would also overwrite the original content (local uncommitted changes), leaving you with alternatives like a VSCode timeline to get your local modification back.但它也会覆盖原始内容(本地未提交的更改),从而为您提供诸如VSCode 时间线之类的替代方案来恢复您的本地修改。

A git restore -p or -m would at least attempt to merge hunks of code between the restore source and the restore location, instead of blindly overwriting everything. git restore -p or -m至少会尝试合并还原源和还原位置之间的代码块,而不是盲目地覆盖所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM