I am a tester and have limited knowledge about Git. I have cloned a project and created a local workspace. When I want to get the latest source code, I use the git pull
command.
Correct me if I am wrong. I think that I don't have a branch.
Now I want to know the changes between my workspace and master. In short I want to know the changes that are going to be applied on my workspace.
I have tried git diff master
, but it returns nothing.
This is the real basics of Git. I strongly recommend going through a visual Git tutorial (just google that). Also, I recommend getting the open source GUI tool Git Extensions so you can visually see your commits/branches and learn different commands easier.
origin
by default) into a local repository on your PC.git fetch
), and then will git merge
your local master
branch into the remote master
branch that you just pulled down.master
branch.git status
.git diff HEAD
.Although it's really easy in Git Extensions to see the current changes - just hit the "Commit" button, and a window pops up with the working directory on top left, index on bottom left, and if you click on any file in them, you'll see all the changes for that file on the right side.
(Sorry - couldn't resist the Star Wars quote)
Okay, I finally understand your core question - you are not making changes to the local repository, you just want to see the changes between the repository before the pull and after the pull - to see what changed since the last time you pulled.
This can be done by getting the hash of the last commit on master
before the pull, and then using:
git diff <hash of prior commit> HEAD
HEAD
refers to whichever commit is currently checked out, either the current commit of the branch you checked out, or a particular commit if you checked one out directly (this is a state called a "detached HEAD"). HEAD
will point to master
which will should point to the latest commit in the repository after a successful pull.
Instead of using HEAD
, you could put the actual hash of the latest commit. Note that if you know how many commits were pulled down, you don't even need to know the commit hashes. For example, if the prior commit was two commits back, you can use:
git diff HEAD~2 HEAD
The HEAD~2 just looks two commits back in the log from HEAD, and uses that hash.
To do this with a GUI, in Git Extensions, you can just right-click on the prior commit and select "Compare → Compare to current branch" in order to pull up the diff window with the changes between that commit and the current location of your current branch.
The currently checked out branch/commit is shown in bold in Git Extensions, and should always be at the top of the list and have a >master
tag next to it for your situation.
In general, you are always on a branch in Git (an exception might the detached head state). Unless you recall creating a branch, my guess is that you are on the master
branch. To see changes you have made relative to where you began, you can use the following from the command line:
git diff HEAD
If you are using an IDE such as IntelliJ or Eclipse, with a Git plugin, then you can visually see many more types of diffs of the files in your workspace.
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