DEV Community

Discussion on: Copy Your Modified Files in Git with 1 line

Collapse
 
grepliz profile image
Liz Lam • Edited

Hmmm...this should work for renamed files. There may be an error for the original file that no longer exists, but that should not stop the command from working. What are you observing?

Collapse
 
sethiadhira profile image
sethiadhira • Edited

True, when you rename the file, eventually file does not exist hence the renamed file is not considered.
I added a small if-else(just for renamed files) in the above statement to make it work for my use case.

git status --porcelain=v1 | awk {' if ($1 == "R") print $4 ; else print $2'} | xargs -I {} cp -r {} modified_files/

Thread Thread
 
grepliz profile image
Liz Lam

Ah I see. You are actually doing a git mv to rename your files. Yes, you are right, in that case your solution is perfect! Thanks for sharing!