How does IPFS retrieve older version

Hi there, I am very glad to join IPFS community. I am new to IPFS.

I found a problem when I did experiments these days. How do I track the older version of my “add”? For instance, I add one file to IPFS, say “file.txt”. I get a hash code “Qm…”, Hash Code One. Then I changed the content , and add it to IPFS again and gain another hash code, Hash Code Two. Can I retrieve Hash Code One based on Hash Code Two? Like Git? I know you can “git log” and then “git reset” to find the old version. Is there any command in IPFS to trace all the version of my files? I know “ipfs pin ls”, but this does not show the dependences and relationship between different versions. It just shows hashes.

I would like to find all the hash of my specific file through the newest one.

Thanks a lot for your help. It would be better if you can give me the commands and show me an example.

1 Like

There’s no current way that I know of to do that with IPFS. I don’t think it would be too difficult to do something like it though. Tracking history of individual files is a little more tricky. Even git doesn’t really track the history of files but tracks the history of content and there is a configurable threshold for what is considered a new version of a file.

What you could do is track the root of a directory with back pointers to previous versions. You’d have to add some sort of call back to update an IPLD document and IPNS record to track the previous version or something like that. Or maybe just add a .prev file with the previous CID to the root and just make sure you somehow skip the update when you add that file or you’d get into a loop. It would be a cool feature to have.

This is a special case of the very common question: "How can I store some metadata (like a few key/value pairs) along with a file. If metadata were allowed you could easily create a standard where any file could optionally point to a known previous version, by having key/value of “prevVersion=[my CID]”

Maybe Orbit DB has versioning capability built in, and implements some kind of ‘reverse linked list’ like that?

You can add them all to a folder and name them like v1,2,3,4…

1 Like

The only problem with just putting all the file versions in a directory that grows forever would be that retrieving any version of the file would require loading the CIDs for every prior version as part of that payload.

But who am I to say that’s a bug and not a feature. Some apps may want to load every version any time they load any version. This is just the basic “array v.s. linked list” choice, although I’m aware data deduplication in the chunker helps make the array approach at least worth considering.

Thanks men. Thank you for your great answers.

Have you ever tried to find the links among blobs? IPFS says that it has version control based on git. So I am wondering if it possible to find out how IPFS works on git, and then track my files.

Once again, thanks a lot.

A folder is just a list of links. No need to load all versions, it is just a way to keep a reference to all versions.

@hector Yeah, CID is synonymous with Link.