The best way to list these file is using git status --porcelain.
For example:
git status --porcelain | awk 'match($1, "D"){print $2}'
shows you the tracked files which have been deleted from the local copy. You can delete all these files by appending an appropriate command to the pipe:
git status --porcelain | awk 'match($1, "D"){print $2}' | xargs git rm
Answer from Alex Sharapov on Stack OverflowThe best way to list these file is using git status --porcelain.
For example:
git status --porcelain | awk 'match($1, "D"){print $2}'
shows you the tracked files which have been deleted from the local copy. You can delete all these files by appending an appropriate command to the pipe:
git status --porcelain | awk 'match($1, "D"){print $2}' | xargs git rm
I'm not sure what you mean by with respect to each other, but if you want an individual listing (e.g. all modified files) you can use git ls-files with the right flags (for modified files it's -m). If you want all of this info at once, you can use git status --porcelain to get a script-parsable output of the status.
made some changes to local files, didn't commit, git says it's up to date
git - How to list only the names of files that changed between two commits - Stack Overflow
git - How do I list all the files in a commit? - Stack Overflow
Is there a way to show the files that are changed on git push?
Git Diff - Inspecting Changes in Git
How can I see file changes between two specific commits?
How do I check modified files in the last commit?
Videos
The result of my git message is:
[main 97e3706] pushing directory 2 files changed, 10 insertions(+) To github.com:mementomoriok/files.git 077584e..97e3706 main -> main
Might there be some way to show the actual file names, instead of "2 files changed" ?
Okay, so say I pulled/fetches some files from repo, then I made some minor changes to some of them.
However, upon realizing I don't want these changes, I now want to have previous version of those files. It's not easy for me to manually edit them back to previous status. So I wanted git to check integrity of these files and see if they match with the remote repo, if not, then replace them.
However, upon doing "git pull" or git fetch or whatever, git says my local repo is up to date.
The only way I can pull the current files from remote repo, is if I clone entire repo, but that's wasteful.
I only need a few files to update. Even if I delete them, I don't know how to force git to add their current versions from remote repo.
git diff --name-only SHA1 SHA2
where you only need to include enough of the SHA hash to identify the commits. The order of the SHAs does not matter. The output (which includes the relative path, not just the file name) follows this format:
dir 1/dir 2/filename.ext
dir 3/dir 4/other filename.ext
You can also do, for example
git diff --name-only HEAD~10 HEAD~5
to see the differences between the tenth latest commit and the fifth latest (or so).
git diff --name-status [SHA1 [SHA2]]
is like --name-only, except you get a simple prefix telling you what happened to the file (modified, deleted, added...)
git log --name-status --oneline [SHA1..SHA2]
is similar, but commits are listed after the commit message, so you can see when a file was changed.
if you're interested in just what happened to certain files/folders you can append
-- <filename> [<filename>...]to thegit logversion.if you want to see what happened for a single commit, call it SHA1, then do
git log --name-status --oneline [SHA1^..SHA1]
File status flags:
| Flag | Name | Meaning |
|---|---|---|
M |
modified | File has been modified |
C |
copy-edit | File has been copied and modified |
R |
rename-edit | File has been renamed and modified |
A |
added | File has been added |
D |
deleted | File has been deleted |
U |
unmerged | File has conflicts after a merge |
Preferred Way (because it's a plumbing command; meant to be programmatic):
$ git diff-tree --no-commit-id --name-only bd61ad98 -r
index.html
javascript/application.js
javascript/ie6.js
Another Way (less preferred for scripts, because it's a porcelain command; meant to be user-facing)
$ git show --pretty="" --name-only bd61ad98
index.html
javascript/application.js
javascript/ie6.js
- The
--no-commit-idsuppresses the commit ID output. - The
--prettyargument specifies an empty format string to avoid the cruft at the beginning. - The
--name-onlyargument shows only the file names that were affected (Thanks Hank). Use--name-statusinstead, if you want to see what happened to each file (Deleted, Modified, Added) - The
-rargument is to recurse into sub-trees
If you want to get the list of changed files:
git diff-tree --no-commit-id --name-only -r <commit-ish>
If you want to get the list of all files in a commit, you can use
git ls-tree --name-only -r <commit-ish>