Skip navigation.
KDE Developer's Journals

git everywhere... (how to compare my stuff to the central repository)

alexander neundorf's picture

KDE will be moving to git, Qt has moved to git, recently also CMake moved to git.

So, it's time to start using git.

...until now it really looks so complicated, compared to cvs/svn.
In cvs/svn it was easy: local working copy, remote central repository, just one step away.
With git this is about three steps away: local working copy, stash, local repository, remote repository. You always have to be aware of where things are.

Ok, one has to get used to that "git add" is something different from "svn add", and "git commit" is different from "svn commit".
After a "git merge --rebase" (which seems to be the same as "svn up"), git told me that some files "need updates".
So I just tried "git update".
This would have been too easy:
git: 'update' is not a git command. See 'git --help'.

Did you mean this?
update-ref
$

Ah, right, I think "git checkout" is the same as "svn update".

At least "git diff" seemed to do the same as "svn diff" (or cvs diff).
Then I committed. To my local repository this means.
Now, I wanted to have a patch which I can send away.
So, with svn/cvs I did "svn diff", so I tried "git diff".
Nothing.
Of course, because there is no difference anymore between my working copy and my local repository.
But how do I get the difference between my local repository and the repository from which I cloned ?

I mean, I'd like to know that before I push.

So, some browsing and googling follows:
http://marklodato.github.com/visual-git-guide/
http://www.kernel.org/pub/software/scm/git/docs/everyday.html
http://book.git-scm.com/3_comparing_commits_-_git_diff.html

I read things like "committing with a detached HEAD" or "Create a local reference to the remote repository as" and other things which sound quite complicated.
I try "git log '^origin/master' master" and then "git format-patch --stdout 62b095d". This looks quite good, but is only one commit, not two. So I try "git format-patch --stdout 62b095d 57c5d370". This gives me plenty weird stuff. Next try.

And finally I find a web page which seems to contain what I'm looking for, how do I compare my stuff to the central repository:
http://pjps.tumblr.com/post/96756489/git-diff-with-a-remote-repository

Phhh, is it really that complicated, doing like one of the most basic things ?

So, how do I do this ?

Alex

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
arichardson's picture

compare with central repo

The easiest way to compare your local changes to the central repo is IMHO "git diff origin/master"
This also includes everything you haven't committed yet.

eike hein's picture

Git resources

FWIW, the best book out there right now happens to be free and online: http://progit.org/book/

Another great read is the "Git Parable:" http://tom.preston-werner.com/2009/05/19/the-git-parable.html

After the parable and the first 3-4 chapters of Pro Git - an evening read, overall - most people should be pretty fit with git.

Just stop trying to use SVN as your frame of reference Smiling.

rich's picture

Techbase Page

I created a 'What on earth does this mean?' page on techbase last night where we can collect confusing messages etc. like those you're seeing in one place. Hopefully we can even get some answers as to what they mean.

http://techbase.kde.org/Development/Tutorials/Git/decoding-git

vdboor's picture

Git all at once?

Sounds like you've got everything at once. And I agree there are many confusing tutorials out there. This prompted me to start writing something as well ( http://codingdomain.com/git/ - it is not finished yet ). The mental model of DVCS are different from SVN. Perhaps it's better not to compare both.

To give some answers to your blog:
* `git add` can be considered as an alias for `git stage`. It adds files to the "staging area" (the place where you prepare your next commit).
* to exchange commits with a remote repository, it needs to be added to your "git remote" list (sort of bookmarks).
* then you can do "git fetch" to retrieve any commits you don't have. (they live side-by-side because the SHA1 identifiers differ)
* the remote commit chains appear as a second branch, which you can merge (connect both ends) or rebase (place your local commits on top).
* to get an overview of where things are, you can use `gitk` or: `git log --graph --all --decorate`

aurélien gâteau's picture

Useful tools and tricks

I think it helps when you are learning git to use some visual tools: they give you a more high-level view. Git itself comes with at least two useful ones: "gitk" to browse your git history and "git gui" to create/edit commits and push changes. They are a bit ugly (tcl/tk!) but works quite well and are damn fast. I personally do most of my commits with "git gui". Note that they must be started from your working copy dir.

If you want something more console-oriented, then make sure you install tig, an ncurses based repository browser ( http://jonas.nitro.dk/tig/ ).

Remote branches is what I find the most complex to handle. That is why I like to use grb ( http://grb.rubyforge.org/ ) for this.

Finally here are a few aliases I set up which can be handy when coming from an svn background. Copy these lines to your $HOME/.gitconfig:

[alias]
up = pull --rebase
st = status
ci = commit

For extra fancyness, you may want these as well:

[color]
branch = auto
diff = auto
status = auto

sebsauer's picture

> is it really that

> is it really that complicated, doing like one of the most basic things ?

Yes, it's an entry barrier and definitive not a small one. I would say its harder then learning cmake Smiling

parkotron's picture

Don't try to figure it out as you go.

I think the real trick to learning git (or any other DVCS for the first time), is not to assume that you can figure it out as you go. Moving from CVS to SVN, that's a pretty safe assumption, but with git, you'll just waste your time.

Invest an hour or two and read through a few tutorials. Once you grasp the basic concepts behind it, things start to become a lot clearer. There's no question that you'll still frequently hit roadblocks and have to resort to Google, but at least you'll have a base of knowledge to build on.

thewtex's picture

easy peasy

git diff HEAD..[remote-name]/[remote-branch]
e.g.
git diff HEAD..origin/master

There is a lot of good git documentation out there -- it help to take an hour to learn the basic concepts. Makes you much more productive in the long run. For instance, the tutorial is a place to get a feel for how to use it.

http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html

panzi's picture

DSCMs

I still like DSCMs much more than SVN & Co. I use mercurial but git is not much different (except, what is this "stash"?). When I want to see what I've changed since my last pull I just fire up hgtk log (or gitk) and look what was the last rev that wasn't committed by me. Then I could do a "hg bundle --base 6047 mychanges.hg". Then I send the bundle to a user who can just pull it, which is exactly the same as if he would have pulled from my repo! That is a cool thing.

Other things I like about hg (which I think most apply to git as well):

  • Full offline work.
  • True open source because forks and cross fork merges are easy.
  • You can create a repo on your usb stick and never lose changes you made to your homework at an university computer again.
  • You can run a webserver from which people can pull (and if you want to which people can push) through "hg serve".
  • Only a tiny cgi script is needed to put a remote hg repository into your universities webspace to which your colleges can push (using e.g. .htaccess for authentication). I always thought that our university should provide a VCS server to us, not just a LAMP+cgi webspace. This way *I* could fix that. Eye-wink
  • The included web interface can paint a tree using the canvas element.
  • ssh access and installed hg at the ssh server (or I guess even a nfs mount) also suffices. No need to run a webserver.

Things that only apply to hg (AFAIK):

  • Nice python API.
  • Extensible through python.
  • Pure python fallback if no native modules (for performance) are available and thus a lot of platforms are supported.
  • TortoiseHg (Windows/*nix+GNOME/OS X) or just the hgtk command from it (yes, its gtk but who cares? it is a nice interface).
  • NetBeans has built-in hg support.

Oh and I think its "git pull --rebase". At least that's what I do when I linearize my history when I want to push changes to amarok. But the hg philosophy is to preserve and not change history. Ok, linearistaion of only local changes should no make a big problem, but jsut in principle history should not change. After all only Guido has a time machine.

Another thing I like about hg is that pull does NOT update the working copy. You can pull and before you update to tip, another head or whatever you can use hgtk to look at what has changed and decide to which rev you really want to update (but if you like you can also do "hg pull --rebase -u" in order to pull, rebase and update at the same time). Oh and hg does not need repacks. Eye-wink

But if you really do not want to use git: git has a pretty good svn bridge. This means it can push/pull to/from an svn server but also act as an svn server itself. I think this git does better than hg.

jhodosh's picture

I think the equivalent of 'hg

I think the equivalent of 'hg pull' is 'git fetch'. 'git pull' runs 'git fetch' and then 'git merge'. AFAIK it's slightly different, since git fetch only updates the tracking branch, but the concept seems very much the same: pull in all new commits and update the tips/heads you didn't create yourself. Am I wrong about that? I use git myself, but only use hg for building projects from repositories.

Also, while TortoiseGit is only for Windows, QGit is cross-platform.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.