I'm somewhat new to Git and what I'm trying to do seems like it should be possible. Basically I've been working off of clone of a repo and have made quite a few local commits. Is there a way to see the diff of the 'sum' of all my changes and the original repo version? I would assume this would be possible because Git will essentially do this when I do a push
.
Here is an example of what I'm trying to do: in gitk I will see something like this:
* - [mybranch] Added '42' to end of answers.txt (local commit)
* - Added 'Hello World' to end of my.txt (local commit)
* - Added 'C#/.NET' to beginning of my.txt (local commit)
* - <[RemoteRepo]> (original repo I cloned from)
How is it I can view the difference of the sum of all my changes to my.txt
and answers.txt
when compared to the original version I checked out from RemoteRepo
?
You can git branch -a to list all branches (local and remote) and then choose the branch name from the list (just remove remotes/ from the remote branch name. Example: git diff main origin/main (where "main" is the local main branch and "origin/main" is a remote, namely the origin and main branch.)
We can view the unpushed git commits using the git command. It will display all the commits that are made locally but not pushed to the remote git repository.
You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.
There are three ways ( two others from other answers given here )
1) git diff origin/master master 2) git diff origin/master..master 3) git diff origin/master...master
First one and second one are same and show changes between the tips of the master and remote master.
Third one shows changes that occurred on the master since branch last push and I think this is the most appropriate one you are looking for
The most ready answer is
git show-branch
What you can do for more control is is use git log
annex git rev-list
:
git log --left-right --graph --cherry-pick \ --oneline branchname...remote/branchname
This is my preferred method and will result in something like
> | fff6bda remote fix < | c8903ee local fix < | 724373c Merge branch 'bla' into bla |\ \ | < | 2faf547 details | < | abbdc47 .... |/ / < | befc181 some tagged commit
Include --decorate and you'll get something close to gitk, git-gui and gitweb:
> | fff6bda remote fix < | c8903ee local fix < | 724373c (tag_4) Merge branch 'bla' into bla |\ \ | < | 2faf547 details | < | abbdc47 .... |/ / < | befc181 (tag_3) some tagged commit
git config alias.lr log --long-option1 --long-option2
' for convenient use git config color.ui auto
' for immediate eye-relief If you wanted all local heads (on all local branches) versus all remote commits (on ditto branches):
git log --decorate --pretty=oneline --all --not --glob=refs/remotes --no-walk
Leave off the no-walk to get all individual revisions. In this case I prefer to use the switches shown earlier (--graph --left-right)
If you want to see merges clearly, include --boundary
Git log
and rev-list
support a whole slew of cunning filtering ability, see the man page
--after '2001-01-01' --until 'last week' --author 'martin' -E -i --grep='fixes #[0123456789]+' -S 'new_debug_function'
and many, many others. This should give you plenty of leverage to get exactly at the info you want with almost zero effort
What resides in stashes, but not on remotes (note there is no way to refer to stashes on remote braches because stashes reside in reflogs, and the reflogs (even for remote branches) always reflect local history[1]):
git log $(git rev-list -g stash) --not --glob=refs/remotes
Notes
this will include any dropped stashes, but not the current stashes
git log $(git fsck --unreachable --full --lost-found | grep ' commit ' | cut -d' ' -f3) \ --no-walk --not --glob=refs/remotes --oneline --decorate
For scripting purposes, replace the use of git log
with git rev-list
and you'll get just the hashes (and some more script-prrof robustness)
[1] See also my prior answer(s) on how to transfer stashes between repos:
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