Reputation: 20385
I am creating a repo for my dotfiles that distribute all over on my machine. I picked the directory with most of the dotfiles and created the git repo there. Now I need to add the dotfiles that are NOT in this git repo directory.
I thought I found a way and did
git --work-tree=/ add /another/path/.vimrc
The file is successfully added and pushed as the first commit. However, later I changed the file. When I did git commit -m 'edit .vimrc'
, I got
On branch master
Your branch is up-to-date with 'origin/master'.
...
no changes added to commit
Why is this the case? Did I add the outside file wrongly?
Upvotes: 0
Views: 483
Reputation: 489858
The --work-tree=/
option changes the work-tree temporarily, for the duration of the single command, git ... add /another/path/.vimrc
.
What gets added to your repository is the remainder of the name. So your repository now has a file named another/path/.vimrc
.
If you had run:
git --work-tree=/another/path add .vimrc
you would have added a file named .vimrc
to your repository.
Later, another Git command such as:
git checkout <revision> -- another/path/.vimrc
or:
git checkout <revision> -- .vimrc
extracts the file (another/path/.vimrc
or .vimrc
) to the current work tree, from the specified revision. That current work tree is whatever you have specified this time with --work-tree=
, or by default, the implied work-tree based on git rev-parse --show-toplevel
.
Upvotes: 1