7.1. More on Dataset nesting¶
You may have noticed how working in the subdataset felt as if you would be
working in an independent dataset – there was no information or influence at
all from the top-level
DataLad-101 superdataset, and you build up a
completely stand-alone history:
$ git log --oneline 809cd06 Provide project description 2d3ea97 [DATALAD RUNCMD] analyze iris data with classification analysis 0e524b8 add script for kNN classification and plotting 5c8ec2d [DATALAD] Added subdataset 777c459 Apply YODA dataset setup 6da6d26 [DATALAD] new dataset
In principle, this is no news to you. From section Dataset nesting and the YODA principles you already know that nesting allows for a modular re-use of any other DataLad dataset, and that this re-use is possible and simple precisely because all of the information is kept within a (sub)dataset.
What is new now, however, is that you applied changes to the dataset. While
you already explored the looks and feels of the
longnow subdataset in
previous sections, you now modified the contents of the
How does this influence the superdataset, and how does this look like in the
superdataset’s history? You know from section Dataset nesting that the
superdataset only stores the state of the subdataset. Upon creation of the
dataset, the very first, initial state of the subdataset was thus recorded in
the superdataset. But now, after you finished your project, your subdataset
evolved. Let’s query the superdataset what it thinks about this.
# move into the superdataset $ cd ../ $ datalad status modified: midterm_project (dataset)
From the superdataset’s perspective, the subdataset appears as being “modified”. Note how it is not individual files that show up as “modified”, but indeed the complete subdataset as a single entity.
What this shows you is that the modifications of the subdataset you performed are not automatically recorded to the superdataset. This makes sense – after all it should be up to you to decide whether you want record something or not –, but it is worth repeating: If you modify a subdataset, you will need to save this in the superdataset in order to have a clean superdataset status.
This point in time in DataLad-101 is a convenient moment to dive a bit deeper into the functions of the datalad status command. If you are interested in this, checkout the dedicated Findoutmore.
More on datalad status
First of all, let’s start with a quick overview of the different content types and content states various datalad status commands in the course of DataLad-101 have shown up to this point:
You have seen the following content types:
notes.txt: any file (or symlink that is a placeholder to an annexed file)
books: any directory that does not qualify for the
symlink, e.g., the
.jgpthat was manually unlocked in section Input and output: any symlink that is not used as a placeholder for an annexed file
dataset, e.g., the
midterm_project: any top-level dataset, or any subdataset that is properly registered in the superdataset
And you have seen the following content states:
The section Miscellaneous file system operations will show you many instances of
state as well.
But beyond understanding the report of datalad status, there is also additional functionality: datalad status can handle status reports for a whole hierarchy of datasets, and it can report on a subset of the content across any number of datasets in this hierarchy by providing selected paths. This is useful as soon as datasets become more complex and contain subdatasets with changing contents.
When performed without any arguments, datalad status will report
the state of the current dataset. However, you can specify a path to any
sub- or superdataset with the
In order to demonstrate this a bit better, we will make sure that not only the
state of the subdataset within the superdataset is modified, but also that the
subdataset contains a modification. For this, let’s add an empty text file into
$ touch midterm_project/an_empty_file
If you are in the root of
DataLad-101, but interested in the status
within the subdataset, simply provide a path (relative to your current location)
to the command:
$ datalad status midterm_project untracked: midterm_project/an_empty_file (file)
Alternatively, to achieve the same, specify the superdataset as the
and provide a path to the subdataset with a trailing path separator like
$ datalad status -d . midterm_project/ untracked: midterm_project/an_empty_file (file)
Note that both of these commands return only the
untracked file and not
modified subdataset because we’re explicitly querying only the
subdataset for its status.
If you however, as done outside of this hidden section, you want to know about
the subdataset record in the superdataset without causing a status query for
the state within the subdataset itself, you can also provide an explicit
path to the dataset (without a trailing path separator). This can be used
to specify a specific subdataset in the case of a dataset with many subdatasets:
$ datalad status -d . midterm_project modified: midterm_project (dataset)
But if you are interested in both the state within the subdataset, and the state of the subdataset within the superdataset, you can combine the two paths:
$ datalad status -d . midterm_project midterm_project/ modified: midterm_project (dataset) untracked: midterm_project/an_empty_file (file)
Finally, if these subtle differences in the paths are not easy to memorize,
-r/--recursive option will also report you both status aspects:
$ datalad status --recursive modified: midterm_project (dataset) untracked: midterm_project/an_empty_file (file)
This still was not all of the available functionality of the
datalad status command. You could for example adjust whether and
how untracked dataset content should be reported with the
option, or get additional information from annexed content with the
option. To get a complete overview on what you could do, check out the technical
documentation of datalad status here.
Before we leave this hidden section, lets undo the modification of the subdataset by removing the untracked file:
$ rm midterm_project/an_empty_file $ datalad status --recursive modified: midterm_project (dataset)
Let’s save the modification of the subdataset into the history of the
superdataset. For this, to avoid confusion, you can specify explicitly to
which dataset you want to save a modification.
-d . specifies the current
DataLad-101, as the dataset to save to:
$ datalad save -d . -m "finished my midterm project" midterm_project add(ok): midterm_project (file) save(ok): . (dataset) action summary: add (ok: 1) save (ok: 1)
More on how save can operate on nested datasets
In a superdataset with subdatasets, datalad save by default tries to figure out on its own which dataset’s history of all available datasets a save should be written to. However, it can reduce confusion or allow specific operations to be very explicit in the command call and tell DataLad where to save what kind of modifications to.
If you want to save the current state of the subdataset into the superdataset
(as necessary here), start a
save from the superdataset and have the
-d/--dataset option point to its root:
# in the root of the superds $ datalad save -d . -m "update subdataset"
If you are in the superdataset, and you want to save an unsaved modification
in a subdataset to the subdatasets history, let
-d/--dataset point to
# in the superds $ datalad save -d path/to/subds -m "modified XY"
The recursive option allows you to save any content underneath the specified directory, and recurse into any potential subdatasets:
$ datalad save . --recursive
Let’s check which subproject commit is now recorded in the superdataset:
$ git log -p -n 1 commit 3a3a860567acf198de5b1a189c83341a2ec11d8f Author: Elena Piscopia <email@example.com> Date: Tue Jun 18 16:13:00 2019 +0000 finished my midterm project diff --git a/midterm_project b/midterm_project index 777c459..809cd06 160000 --- a/midterm_project +++ b/midterm_project @@ -1 +1 @@ -Subproject commit 777c4596c9d2c0192326eb4f1a6eb170e8bf57ae +Subproject commit 809cd069ed90b7e0e69018c545d30a3e3616580e
As you can see in the log entry, the subproject commit changed from the
first commit hash in the subdataset history to the most recent one. With this
change, therefore, your superdataset tracks the most recent version of
midterm_project dataset, and your dataset’s status is clean again.