Could I do take commit my changes in a directory by a daily routine? Say, In every 12 AM at early morning, It should commit all the changes in that directory automatically? Is it possible in git? I get some answers for auto commit for every changes. But I want it for daily once commit.
-
4You might want to Thing a little more about what an SCM can do for you! Committing a random state into your repository is almost never what you want. A better choice would be every time your Project compiles (and all automated tests are passing). However, this should always be an explicit decision.– Timothy TruckleSep 4, 2018 at 7:21
1 Answer
If you simply want to commit ALL changes every morning at 12 AM, you can do this using a cronjob.
Assuming that you are using a linux distribution with bash, you can write a bash script that does the commit
#!/bin/bash
cd <git directory> && git add -A && git commit * --allow-empty-message -m ''
Then you can place this cron job in /etc/cron.d/
0 0 * * * <username> /bin/bash <script location>
If you intend to run this as your own user only then you can instead add it to your personal crontab interactively by running
crontab -e
-
1downvoted because while this solution is technically correct it does not address the potential missuse of the SCM. Sep 4, 2018 at 7:23
-
3His usage makes sense if he intends to use git to track certain results, it doesn't always have to be code. Sep 4, 2018 at 7:25
-
1
-
2Downvoted because
git commit
without-m
starts the configured editor and waits for it to exit. It doesn't work when it is launched by the cron daemon.git commit *
is even worse because the*
wildcard is expanded by the shell to the list of files and directories in the current directory. It generates a command line you don't control and that also won't work (unless there is a file named-m
in the project).– axiacSep 4, 2018 at 7:38 -
2Also,
git add *
does not add the hidden files (whose names start with.
). The correct way to add to the index all the new, modified and removed files isgit add -A
– axiacSep 4, 2018 at 7:42