Reputation: 17900
I have a script that detects changes in file.txt
and if changes are present, commits and pushes them. I thought of doing this by issueing a git diff
to see whether the file has changed.
Now, there are 2 cases I could think of:
git diff --name-only --cached
to see that the file should be pushed;git diff --name-only
to see that the file should be pushed.My questions are:
git add <file>
safe any way it is being used? Meaning, if the file is tracked/untracked, it has been staged/has not been staged yet etc.Upvotes: 2
Views: 67
Reputation: 387507
Just use git status
. You can use the --porcelain
parameter to get a concise machine-readable output which you can easily parse.
Also, you can always just use git add filename
(or git add .
for everything in the current directory) to stage files. If they have not been modified, then nothing will happen, and if there are changes, those changes will be staged. And similarly, if it hasn’t been tracked before, it will be tracked and staged then. You could also use git add -u
to just update all already-staged files, staging any changes (even file deletions).
Upvotes: 4