Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我创建一个新分支然后删除文件,我可以通过签出以前的提交来取回它们吗?
例如:
git checkout -b get-rid-of-useless-files
rm useless.js
不好了!
git checkout
呸(?)
是的,如果文件已经签入并且您将其删除,则可以将其取回:
git checkout -- path/to/deleted/file
要添加到 manojids 答案,如果你已经git rm /path/to/deleted/file可以git reset HEAD /path/to/deleted/file,然后git checkout -- /path/to/deleted/file
git rm /path/to/deleted/file
git reset HEAD /path/to/deleted/file
git checkout -- /path/to/deleted/file