Hakim
Hakim

Reputation: 3437

Git diff HEAD before ever commiting

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

Answers (4)

John Jesus
John Jesus

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

Jokester
Jokester

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

Mattias Wadman
Mattias Wadman

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

kenchilada
kenchilada

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

Related Questions