Reputation: 3437
I'm quite new to Git. My question concern the execution of the git diff HEAD
command before ever commiting. I know that HEAD doesnt exist until I had commited something. So how do I do to get the difference between working directory & the initial state of the repo.
I know that this command gives the difference between working directory & the index (Stage):
git diff
And that the following command gives the difference between the index & the repo:
git diff --cached
Upvotes: 0
Views: 107
Reputation: 2404
Usually my initial commit is simply a README file. That forces me to create a README and I can also check that my push to remotes are working. My first real
commit of actual code follows that one, and, so, the regular git diff
at this point works as you're intending it.
Upvotes: 1
Reputation: 5617
To have a HEAD to compare against, you can create an empty commit by git commit --allow-empty
immediately after git init
.
Upvotes: 1
Reputation: 11425
I guess you could do a git commit --allow-empty
without adding anything if you you really really want to diff the first "real" commit that adds things.
Upvotes: 3
Reputation: 7559
Maybe you want git status
? If you have a newly-initialized repository with no commits, there will not be much of interest yet.
You can use git add .
to slurp everything in the current directory to the staging index and then commit.
After your first commit, you will be able to see any further changes using git diff
.
Upvotes: 0