File not shown in git diff after a git add. How do I know it will be committed?
Solution 1
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.
Solution 2
To see all the changes in the working tree since your last commit including new files use:
git diff HEAD
See more examples here: git-diff
Solution 3
As you've seen. it shows in git status
, so yes it will be committed when you git commit
it.
You may find it helpful to use a visual git tool such as gitx (Mac) or gitg (Linux),
It has nice panels to show you staged, not staged, etc.
My screenshot seems spare as I currently have no changes in that status.
Solution 4
If you typed in "git add __", the file will be included in your next commit. This commit will be pushed to the server when you run "git push".
Kitty1911
Updated on August 01, 2020Comments
-
Kitty1911 over 3 years
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?
-
Stephen over 8 yearsWhat good is this answer? How about if you want to just take a manual patch for some reason. (dont bother replying with why would you want to? there are hundreds of reasons why i'd want to)
-
tom over 8 years@Stephen, this is an answer I wrote 2 years ago, and so I'm taking a guess as to what my thought process was back then. The OP's post ends with the question "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?". This is a direct answer to that question.
-
DZet over 3 yearsIf, in the mean time, you create changes to the staged files, those changes will show in
git diff
andgit diff --staged
will only show the staged files at the point at which they were staged.