Reputation: 7855
I want to "pluck" (if that's a good word for it) just the unstaged files and copy them to a different directory. I don't want any other files in the repo... just these unstaged files.
Is there a git command or shell + git command to do this?
Updating question to respond to questions:
Upvotes: 3
Views: 876
Reputation: 60443
git ls-files -m | tar Tc - | tar Cx /path/to/other/dir
and if windows wasn't a factor I'd do the tarpipe thing with just cpio -pd /path/to/other
.
Upvotes: 9
Reputation: 30888
prefix=/xxx/
git status --porcelain | grep -e "^ M " | while read mark path
do
mkdir -p $prefix/$(dirname "$path")
cp -v "$path" $prefix/"$path"
done
prefix
is the root folder of the backups.
Upvotes: 0
Reputation: 290075
If you use -s
for --short
you can get the list of files in a nice (porcelain) way:
$ git status -s
M dir1/file1.py
M dir2/file2.py
So then it is just a matter of looping through this list using process substitution:
while IFS=" " read -r _ file; do
echo "$file --" # or whatever "mv" you want to do
done < <(git status -s)
This slurps the first column using the throw away variable _
and the rest is stored in $file
.
Upvotes: -1