简体   繁体   English

如何在git索引中取消重命名的文件?

[英]how to unstage a renamed file in git index?

I'm always using git checkout <file> to unstage uncommited changes, however I can't seem to do this when files were renamed. 我总是使用git checkout <file>来取消未经修改的更改,但是在重命名文件时我似乎无法做到这一点。

git just can't pickup the file I want to unstaged, tried this with no luck: git只是无法拾取我想要取消暂停的文件,试试这个没有运气:

git checkout <oldfilename>

and

git checkout <newfilename>

returns error: pathspec '<file>' did not match any file(s) known to git. 返回error: pathspec '<file>' did not match any file(s) known to git.

Use git reset -- newfilename to unstage the renamed file. 使用git reset -- newfilenamegit reset -- newfilename重命名的文件。

If instead of unstaging you are looking to rename the file back, use git mv newfilename oldfilename . 如果您要重新命名文件而不是取消git mv newfilename oldfilename ,请使用git mv newfilename oldfilename

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

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