简体   繁体   English

文件未与 git status 一起列出并在提交后丢失

[英]Files were not listed with git status and got lost after a commit

I lost files from my local repo.我丢失了本地存储库中的文件。 by "mistake" after using git.使用 git 后的“错误”。 Am trying to understand that mistake and undo it if possible.我试图理解这个错误,并在可能的情况下将其撤消。 what I did sequentially is:我依次做的是:

git status
git add -A
git commit -m "some message"
git push origin master

The weird part is that I had some new files (since the last commit) that did not get committed and pushed, and now do not exist on my local repo.奇怪的是,我有一些新文件(自上次提交以来)没有提交和推送,现在我的本地存储库中不存在。

Looking more into it, I saw that my git status did not list these files in the first place.深入研究,我发现我的 git status 一开始并没有列出这些文件。 These are the files that I lost.这些是我丢失的文件。 Why would that happen ?为什么会这样? and is there a way to get them back ?有没有办法让他们回来?

I have git version 1.8.3.1我有 git 版本1.8.3.1

If you didn't add the files to git at any point, it's unlikely you can recover them using git.如果您在任何时候都没有将文件添加到 git,则不太可能使用 git 恢复它们。 You can see if they are in your repository by this handy "one-liner"您可以通过这个方便的“单行”查看它们是否在您的存储库中

alias gitobjects="git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %
       │ (objectname) %(objectsize) %(rest)' | sed -n 's/^blob //p' | sort --numeric-sort --key=2 | c
       │ ut -c 1-12,41- | numfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest"
gitobjects | grep "myfile"

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

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