Posts tagged git
Posts tagged git
I always wondered why tags where not transferred, but I never felt the need to look it up. Today I saw it by pure chance while looking up something else ;-)
Very cool: E. coli sequence data on github.
At work, I sometimes (well, actually quite often) need to merge commits from different repositories or branches. Usually, I do not want all of them, only some.
This is where git’s cherry-pick command comes in. Basically, it applies a specific commit to your current repository, for example
git cherry-pick 727af6f5c7a7c65df6e300be58c9aa369da976e0
My old workflow was like this:
git fetch some-remote-repository— fetch the updates (new commits) to the remote repository
git log -p master..some-remote-repository/master— list the changes (commits) to the remote repository
This works nicely, but it does not scale if you have more than, say, half a dozen commits. Then the copy-paste business becomes very annoying.
So I was looking for a better workflow. I had a look at various GUI tools, but none of them (after an admittedly superficial look …) allowed me to cherry-pick from a remote repository. I am quite sure that some of them can do this somehow, but I did not find a way to either (a) specify the remote repository and fetch the data or (b) cherry-pick.
Neither asking for input on Twitter, nor Google provided me with a satisfactory answer.
After playing with tig, a curses-based git client, for a while, I found out that it supports cherry picking - by entering “C” when the relevant commit is selected. So the missing piece was to find out how to get the information about the remote repository. It turns out to be quite easy as well: Just start tig with the remote branch name.
So now it is:
git fetch some-remote-repository
Here is a screenshot of tig:
Navigation in tig is very similar to
less, you can use “/” to search, and “h” for help. Press “q” for quitting the help again.
If you are using a GUI git client (free as in liberty, on Linux) regularly, and know how to perform cherry-picking in an elegant/efficient way, I would like to hear from you.
July 1, 2011: If you want to add a new remote repository you want refer to as some-remote-repository as above, you need to use this command:
git remote add some-remote-repository URL, e.g.
git remote add MML-github firstname.lastname@example.org:zenogantner/wikipedia-tools.git
… some new things about git: How to push things to remote branches, and how to push things to several remote repositories at once (thanks to Carsten for the hint).
Currently, I am re-working some underlying data structures of MyMediaLite, the recommender system library that I (well, mostly me) develop. This breaks things BIG TIME, and for quite a while. In other words, a really good case for branching.
I knew how local branching and merging works, but I had no idea how to push the contents of branches to a remote repository without pushing it to the remote master branch.
It turns out it is quite easy:
git push email@example.com:mymedialite/mymedialite.git new_ratings:new_ratings
Well, everything looks easy with git once you find out how to do it. It was not obvious to me, and reading the man pages also did not really help.
Pushing to Several Remote Repositories
[remote "MML"] url = firstname.lastname@example.org:mymedialite/mymedialite.git url = email@example.com:zenogantner/MyMediaLite.git
I can then use the MML alias to push to both repositories:
git push MML
Combining Both Features
And guess what, of course the two features can be combined without a problem:
git push MML new_ratings:new_ratings