Reputation: 4799
I'm on my "devel" branch and git status
says "working directory clean".
I want to look at a past release and so checkout a tag: git checkout tags/v1.0.0
. After this some directories which were created between "v1.0.0" and my current "devel" HEAD are left empty but not removed (although they didn't exist when the tag was created). I believe this is because git doesn't track empty directories.
In order to have exactly the same state as when the tag was created, I additionally need to call git clean -fd
which removes these remaining empty directories.
When I checkout a tag, I want the exact state of the filesystem when that tag was created - should I always call git clean -fd
after a checkout?
Upvotes: 1
Views: 444
Reputation: 7007
Your observations could potentially be explained by a change in your .gitignore
:
Assume that you're currently in your "devel" branch but have an untracked "foo" directory. If "foo" is listed in your .gitignore
, git status
will (correctly) report a clean working directory.
If you now checkout your tagged version, it could contain a different .gitignore
(not ignoring the "foo" directory) and your working directory would now look dirty.
When I checkout a tag, I want the exact state of the filesystem when that tag was created
Given that you can change your .gitignore
(in your repo or even globally) and the fact that git will never silently delete any untracked files, this won't always be possible without an additional call to git clean -fd
.
Upvotes: 0
Reputation: 76837
Yes, you will need to clean the directories manually since directories are never tracked in git, only files are.
To do this in one step, you can define a shell function as a git alias to do this for you in a single step.
Either do the following in your terminal:
git config alias.cco "! f(){ git checkout \"\$1\" && git clean -fd; }; f"
or edit your .git/config
file and add this entry there:
[alias]
cco = "! f(){ git checkout \"$1\" && git clean -fd; }; f"
Now, you can run both these commands in a single go using:
git cco tag_name
Upvotes: 1