简体   繁体   English

如何清除git树中列出的哪些文件是特定提交的一部分?

[英]How is it clear which of the files listed in a git tree are part of a specific commit?

A commit in git has a reference to a tree and that tree references blobs or other trees and captures a "snapshot" of the project. git中的提交引用了树,该树引用了blob或其他树并捕获了项目的“快照”。
What I am not clear about is how the association is done between a specific commit with the actual files affected by the commit. 我尚不清楚的是如何在特定提交与受该提交影响的实际文件之间建立关联。
Example in my project I have the files README and notes.txt . 在我的项目中,示例有READMEnotes.txt文件。
If I add a new file eg contracts.txt and commit it I would have the new commit XYZ and if I did git show XYZ I would see only the file contracts.txt listed. 如果我添加一个新文件,例如contracts.txt并提交,我将拥有新的提交XYZ ,如果我进行git show XYZ我只会看到列出的文件contracts.txt
But if I do git cat-file -p XYZ I would see that its associated tree is ABC which doing git cat-file -p ABC would show: 但是,如果我执行git cat-file -p XYZ我会看到它的关联树是ABC ,执行git cat-file -p ABC将会显示:

blob F123 README  
blob A0F8 notes.txt  
blob DA03 contract.txt  

So I can't tell from this how could we figure out that from these 3 reported blobs reported as part of the tree, only DA03 contract.txt was added as part of the commit XYZ . 因此,我不能从中知道如何从这三个报告为树的一部分的报告斑点中DA03 contract.txt作为提交XYZ一部分。
How is the association done? 关联如何完成?

Simply: by comparing with the same information from the parent commit. 简单:通过与父提交中的相同信息进行比较。 For merges, the comparison is done with all the parents. 对于合并,将与所有父母进行比较。 Only blobs which don't come from either (thus are new files or new versions thereof; in the case of merges, also resolutions of merge conflicts) are shown by git show . git show仅显示不来自两者的Blob(因此是新文件或新版本;在合并的情况下,也是合并冲突的解决方案)。

What I am not clear about is how the association is done between a specific commit with the actual files affected by the commit. 我尚不清楚的是如何在特定提交与受该提交影响的实际文件之间建立关联。

Git does not make such associations, it simply stores the snapshot of the repository for each commit. Git没有建立这种关联,它只是为每次提交存储存储库的快照。 Diff tools display the files as new if they don't exist in the parent commit. 如果父提交中不存在差异工具,则它们会将文件显示为新文件。

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

相关问题 获取最后一次提交的git commit hash,它会影响类似.gitignore的文件中未列出的文件 - get the git commit hash of the last commit which affected files not listed in a .gitignore-like file 在特定提交时在裸git repo中获取文件树 - Get a tree of files in a bare git repo on at a specific commit 如何知道在git commit中删除了哪些文件? - How to know which files is deleted in a git commit? 如何使用不在工作树中的提交清理 git 存储库 - How clean git repository with commit which not in work tree 如何在强制推送后下载特定的git树或提交 - How to download a specific git tree or commit after force push 文件未与 git status 一起列出并在提交后丢失 - Files were not listed with git status and got lost after a commit git:两次提交之间的差异,仅适用于第三次提交中列出的文件? - git: diff between two commits, only for the files listed in a third commit? git 状态显示.gitignore 中列出的文件的“更改未暂存以进行提交”? - git status is showing "Changes not staged for commit" for files listed in .gitignore? 如何查找git存储库中的哪个标记包含特定的提交 - How to find which tag in a git repository contains a specific commit 如何确定哪个提交删除了git中的特定行? - How to determine which commit deleted a specific line in git?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM