Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 views
in Technique[技术] by (71.8m points)

git - 查找在Git中删除文件的时间(Find when a file was deleted in Git)

I have a Git repository with n commits.

(我有一个带有n次提交的Git存储库。)

I have a file that I need, and that used to be in the repository, and that I suddenly look for and think "Oh! Where'd that file go?"

(我有一个我需要的文件,而且曾经存放在存储库中,我突然想到并想“哦!那个文件去哪了?”)

Is there a (series of) Git command(s) that will tell me that "file really_needed.txt was deleted at commit n-13"?

(是否有(系列)Git命令会告诉我“在提交n-13时删除了文件really_needed.txt”?)

In other words, without looking at every individual commit, and knowing that my Git repo has every change of every file, can I quickly find the last commit that HAS that file, so I can get it back?

(换句话说,如果不查看每个单独的提交,并且知道我的Git repo对每个文件进行了每次更改,我是否可以快速找到该文件的最后一次提交,以便我可以将其恢复?)

  ask by JohnMetta translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

git log --full-history -- [file path] shows the changes of a file, work even if the file was deleted.

(git log --full-history -- [file path]显示git log --full-history -- [file path]的更改,即使文件被删除也能正常工作。)

Example:

(例:)

git log --full-history  -- myfile

If you want to see only the last commit, which deleted a file use -1 in addition, eg, git log --full-history -1 -- [file path]

(如果你想只看到最后一次提交,删除文件另外使用-1,例如, git log --full-history -1 -- [file path])

See Which commit deleted a file

(请参阅哪个提交删除了文件)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...