I work locally under Windows. I have a local git repo and already included some files. The folder (and subfolders) where I am working in includes many other files that are not yet tracked and not known to git. Some of these files have not been changed for many months. I need to add some, but not all of these files. The criterium for inclusion should be the date of last change (e.g. I want to "git add" only files that have been modified within the last month).
Is there a way to do this? Searching help files and threads here only showed me solutions when the files are already tracked.
CodePudding user response:
Not possible with git only, but if you have "git bash" or WSL available, you should be able to run something like
find . -type f -mtime -31 -not -path '*/.git/*' -exec git add -v -- {}
to add files modified within the last 31 days.
Notes:
- If you only want to include certain folders, specify their names instead of
. - To list which files are being matched by the specified age,
run the command without the-execpart:find . -type f -mtime -31 -not -path '*/.git/*' - To list which files would be added without actually adding them,
usegit add's--dry-runoption (short:-n):find . -type f -mtime -31 -not -path '*/.git/*' -exec git add -v -n -- {}
Edit history:
- Instead of
find's-printexpression usegit add's-voption (a.k.a.--verbose). This way only the files that were actually added are listed, not all files that were passed to thegit addcommand. - Add dry-run suggestion to notes
