linkyndy
linkyndy

Reputation: 17900

Way to see with git if a file has been changed?

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:

My questions are:

Upvotes: 2

Views: 67

Answers (1)

poke
poke

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

Related Questions