I had an untracked file which was not appearing in a git diff and when I added it to the 'changes to be committed' area, it still doesn't show up in the git diff. I shows up with a git status -v
when I do a diff against HEAD.
I'm still very new to git, so could anyone please tell me if the file will be committed even if it doesn't show up in a regular diff, as it has been added to the staging area?
There is no output to git diff because Git doesn't see any changes inside your repository, only files outside the repository, which it considers 'untracked' and so ignores when generating a diff.
If you'd like to see the staged changes in a diff, you can still use git diff
, you just need to pass the --staged
flag:
david@pav:~/dummy_repo$ echo "Hello, world" > hello.txt david@pav:~/dummy_repo$ git status # On branch master # # Initial commit # # Untracked files: # hello.txt nothing added to commit but untracked files present david@pav:~/dummy_repo$ git add hello.txt david@pav:~/dummy_repo$ git diff david@pav:~/dummy_repo$ git diff --staged diff --git a/hello.txt b/hello.txt new file mode 100644 index 0000000..76d5293 --- /dev/null +++ b/hello.txt @@ -0,0 +1 @@ +Hello, world
If you only care about which files are staged, you can of course do a git status
, but git diff --staged --name-only
will give each staged filename on its own line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With