I don't think you can use IPNS to store more than one CID (hash) but however you can use IPLD (IPFS Linked Data) to generate a JSON bundle that will reference each version and only the CID of the bundle will be store on IPNS.
Let's do an example:
i. Create a file myfile.txt
containing first version
and store it on IPFS
$ echo "first version" > myfile.txt
$ ipfs add myfile.txt
added QmUCr8K6pNZib5TZ2KAPupdjCqEjpgrm94DJ4UtEQQsuqz myfile.txt
ii. Generate an IPFS bundle referencing this file as version 1
Basically IPLD allows you to store a JSON object on IPFS where leaves can contain data or links.
$ echo '{"version1": {"content": {"/": "QmUCr8K6pNZib5TZ2KAPupdjCqEjpgrm94DJ4UtEQQsuqz"}, "author": "greg"}}' | ipfs dag put
zdpuAqidKVQqA36feYLTLyWV9s4eajMtSmVFJxWpa65o5VFPU
Then we can explore the IPLD bundle like this
o Get the entire bundle
$ ipfs dag get zdpuAqidKVQqA36feYLTLyWV9s4eajMtSmVFJxWpa65o5VFPU
{"version1":{"author":"greg","content":{"/":"QmUCr8K6pNZib5TZ2KAPupdjCqEjpgrm94DJ4UtEQQsuqz"}}}
o Get a specific data within the object
$ ipfs dag get zdpuAqidKVQqA36feYLTLyWV9s4eajMtSmVFJxWpa65o5VFPU/version1/author
"greg"
o Get a specific content through a link
$ ipfs cat zdpuAqidKVQqA36feYLTLyWV9s4eajMtSmVFJxWpa65o5VFPU/version1/content
first version
iii. Store the IPLD hash on IPNS
This IPLD CID has a content addressable hash zdpuAqidKVQqA36feYLTLyWV9s4eajMtSmVFJxWpa65o5VFPU
like any other objects on IPFS and can be stored on IPNS
o Generate the key key
$ ipfs key gen --type=rsa --size=2048 key
QmPU6xFfHykL7HBNbckzB9pCCeVFUx2HD4KxvkQmcYAV6a
o Publish the IPLD CID under this name
$ ipfs name publish --key=key zdpuAqidKVQqA36feYLTLyWV9s4eajMtSmVFJxWpa65o5VFPU
Published to QmPU6xFfHykL7HBNbckzB9pCCeVFUx2HD4KxvkQmcYAV6a: /ipfs/zdpuAqidKVQqA36feYLTLyWV9s4eajMtSmVFJxWpa65o5VFPU
o You can then resolve the name and access the version
$ ipfs dag get $(ipfs name resolve QmPU6xFfHykL7HBNbckzB9pCCeVFUx2HD4KxvkQmcYAV6a)/version1/author
"greg"
$ ipfs cat $(ipfs name resolve QmPU6xFfHykL7HBNbckzB9pCCeVFUx2HD4KxvkQmcYAV6a)/version1/content
first version
iv. Let's now create a second version and upload it on IPFS
$ echo "second version" > myfile.txt
$ ipfs add myfile.txt
added QmNs9wW2s3fVR3aRJS62Ak8honGdB6PEDjF15FnTWnFeu8 myfile.txt
v. We can recreate a new bundle with the second version
$ echo '{"version1":{"author":"greg","content":{"/":"QmUCr8K6pNZib5TZ2KAPupdjCqEjpgrm94DJ4UtEQQsuqz"}}, "version2":{"author":"mani2020","content":{"/":"QmNs9wW2s3fVR3aRJS62Ak8honGdB6PEDjF15FnTWnFeu8"}}}' | ipfs dag put
zdpuAvKvo6QuvQnwtwYhQrsG82iwgGH4bxZpvKY4hrPuKWxaj
And access the data and links
$ ipfs dag get zdpuAvKvo6QuvQnwtwYhQrsG82iwgGH4bxZpvKY4hrPuKWxaj/version1/author
"greg"
$ ipfs cat zdpuAvKvo6QuvQnwtwYhQrsG82iwgGH4bxZpvKY4hrPuKWxaj/version1/content
first version
$ ipfs dag get zdpuAvKvo6QuvQnwtwYhQrsG82iwgGH4bxZpvKY4hrPuKWxaj/version2/author
"mani2020"
$ ipfs cat zdpuAvKvo6QuvQnwtwYhQrsG82iwgGH4bxZpvKY4hrPuKWxaj/version2/content
second version
vi. Finally we only need to republish the new hash of the second bundle
$ ipfs name publish --key=key zdpuAvKvo6QuvQnwtwYhQrsG82iwgGH4bxZpvKY4hrPuKWxaj
Published to QmPU6xFfHykL7HBNbckzB9pCCeVFUx2HD4KxvkQmcYAV6a: /ipfs/zdpuAvKvo6QuvQnwtwYhQrsG82iwgGH4bxZpvKY4hrPuKWxaj
$ ipfs dag get $(ipfs name resolve QmPU6xFfHykL7HBNbckzB9pCCeVFUx2HD4KxvkQmcYAV6a)/version1/author
"greg"
$ ipfs cat $(ipfs name resolve QmPU6xFfHykL7HBNbckzB9pCCeVFUx2HD4KxvkQmcYAV6a)/version1/content
first version
$ ipfs dag get $(ipfs name resolve QmPU6xFfHykL7HBNbckzB9pCCeVFUx2HD4KxvkQmcYAV6a)/version2/author
"mani2020"
$ ipfs cat $(ipfs name resolve QmPU6xFfHykL7HBNbckzB9pCCeVFUx2HD4KxvkQmcYAV6a)/version2/content
second version
And so on and so forth !
Notes:
- Pinning: If you pin the IPLD Bundle, all linked data will be pinned.