From c1bc4b763a4469a7345ff339cfb0dc95e6cbe2b3 Mon Sep 17 00:00:00 2001 From: Ben Lynn Date: Tue, 20 May 2008 01:43:26 -0700 Subject: [PATCH] Described cherry-picks. Minor edits. --- basic.txt | 20 ++++++++++---------- branch.txt | 20 +++++++++++++++++--- grandmaster.txt | 8 ++++---- intro.txt | 6 +++--- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/basic.txt b/basic.txt index ca39b9d..d6d868b 100644 --- a/basic.txt +++ b/basic.txt @@ -1,6 +1,6 @@ == Basic Tricks == -Rather than diving into a sea of Git commands, use these elementary examples to get your feet wet. Despite their simplicity, each of them are useful in real life. +Rather than diving into a sea of Git commands, use these elementary examples to get your feet wet. Despite their simplicity, each of them are useful. === Saving State === @@ -87,11 +87,11 @@ In a court of law, events can be stricken from the record. Likewise, you can pic $ git commit -a $ git revert SHA1_HASH -will undo just the commit with the given hash. Running *git log* reveals the revert is recorded as new commit. +will undo just the commit with the given hash. Running *git log* reveals the revert is recorded as a new commit. === Dowloading Files === -If a project uses Git to manage its files, you can get a copy with: +Get a copy of a project managed with Git by typing: $ git clone git://server/path/to/files @@ -99,17 +99,17 @@ For example, to get all the files I used to create this site: $ git clone git://git.or.cz/gitmagic.git -We'll have a lot more to say about the *clone* command later. +We'll have much to say about the *clone* command soon. === The Bleeding Edge === -If a project uses Git to manage its files, and you've already downloaded a copy using *git clone*, you can upgrade to the latest version with: +If you've already downloaded a copy of a project using *git clone*, you can upgrade to the latest version with: $ git pull === Instant Publishing === -Let's say you've written a script you'd like to share with others. You could just tell them to download from your computer, but if they do so while you're improving the script or making experimental changes, they could wind up in trouble. Of course, this is why release cycles exist. Code is written, and at certain points in time, when it's suitable for others, it gets released. +Let's say you've written a script you'd like to share with others. You could just tell them to download from your computer, but if they do so while you're improving the script or making experimental changes, they could wind up in trouble. Of course, this is why release cycles exist. Developers work on code, and when they feel it's suitable for others, they release the code. To do this with Git, in the directory where your script resides: @@ -117,19 +117,19 @@ To do this with Git, in the directory where your script resides: $ git add . $ git commit -m "First release" -Then tell your users to type +Then tell your users to run: $ git clone your.computer:/path/to/script -to download your script. This assumes they have ssh access. If not, run *git daemon* and tell your users to type +to download your script. This assumes they have ssh access. If not, run *git daemon* and tell your users to instead run: $ git clone git://your.computer/path/to/script -From now on, every time your script is ready for release, type: +From now on, every time your script is ready for release, execute: $ git commit -a -m "Next release" -and your users can upgrade their version by changing to the directory containing your script and typing. +and your users can upgrade their version by changing to the directory containing your script and typing: $ git pull diff --git a/branch.txt b/branch.txt index 7e1ad18..8224d5f 100644 --- a/branch.txt +++ b/branch.txt @@ -117,6 +117,20 @@ and again, the second part is ready to be reviewed. It's easy to extend this trick for any number of parts. +=== Reorganizing a Medley Branch === + +Perhaps you like to work on all aspects of a project in the same branch, but want others to avoid seeing works-in-progress, and want your commits neatly organized. Then after cloning: + + $ git checkout -b sanitized + $ git checkout -b medley + +Next, work on anything: fix bugs, add features, add temporary code, and so forth. and commit often along the way. Then: + + $ git checkout sanitized + $ git cherry-pick SHA1_HASH + +applies a given commit to the "sanitized" branch. With appropriate cherry-picks you can construct a branch that contains only permanent code, and has related commits grouped together. + === Managing Branches === Type: @@ -143,10 +157,10 @@ The equivalent of branching and cloning in centralized version control systems, Most importantly, these operations will be slower to some degree, usually to the point where users won't bother using them unless absolutely necessary. And when they absolutely have to run slow commands, productivity suffers because of an interrupted work flow. -I experienced these phenomena first-hand. Git was the first version control system I used, and I grew accustomed to it, taking many features for granted. I did not know what centralized systems were like, and assumed they were similar. Later, I was forced to use one because of a project I worked on. +I experienced these phenomena first-hand. Git was the first version control system I used, and I grew accustomed to it, taking many features for granted. I did not know what centralized systems were like, and assumed they were similar. Later, I was forced to use one. -Often I have a flaky internet connection. I didn't mind too much with Git but found development unbearable with a centralized system. +Often I have a flaky internet connection. This matters little with Git, but makes development unbearable with a centralized system. -I found myself conditioned to avoid certain commands because of the latencies involved, which ultimately prevented me from following the work flow I wanted. +Additionally, I found myself conditioned to avoid certain commands because of the latencies involved, which ultimately prevented me from following the work flow I wanted. When I had to run a slow command, the interruption to my train of thought dealt a disproportionate amount of damage. While waiting for server communcation to complete, I'd do something else to pass the time, such as check email or write documentation. By the time I returned to the original task, the command had already finished long ago. I would then spend a long time trying to remember what I was doing. diff --git a/grandmaster.txt b/grandmaster.txt index 3a2c40a..93cd66b 100644 --- a/grandmaster.txt +++ b/grandmaster.txt @@ -4,13 +4,13 @@ This pretentiously named page is my dumping ground for uncategorized Git tricks. === Source Releases === -For my projects, Git tracks exactly the files I'd like to archive and release to users. So to create a tarball of the source code, I run: +For my projects, Git tracks exactly the files I'd like to archive and release to users. To create a tarball of the source code, I run: $ git archive --format=tar --prefix=proj-1.2.3/ HEAD === Changelog Generation === -It's good practice to keep a http://en.wikipedia.org/wiki/Changelog[changelog], and some projects even require it. If you've been committing frequently, which you should, generate a Changelog by typing +It's good practice to keep a http://en.wikipedia.org/wiki/Changelog[changelog], and some projects even require it. If you've been committing frequently, which you should, generate a Changelog by typing: $ git log > ChangeLog @@ -27,11 +27,11 @@ and in the "proj.git" directory, run $ git --bare update-server-info $ chmod a+x hooks/post-update -From your computer, you can push via ssh: +From your computer, push via ssh: $ git push web.server:/path/to/proj.git master -and people can get your project via +and others get your project via: $ git clone http://web.server/proj.git diff --git a/intro.txt b/intro.txt index b6c770c..4f03210 100644 --- a/intro.txt +++ b/intro.txt @@ -14,15 +14,15 @@ But this will overwrite the old version. It's like those old school games which When editing, you can "Save As..." a different file, or copy the file somewhere first before saving if you want to savour old versions. Maybe compress them too to save space. This is a primitive and labour-intensive form of version control. Computer games improved on this long ago, many of them providing multiple automatically timestamped save slots. -Let's make the problem slightly tougher now. Say you have a bunch of files that go together, such as collection of source code for the same project, or files for a website. Now if you want to keep an old version you have to archive a whole directory of stuff. Keeping many versions around by hand is inconvenient, and quickly becomes expensive. +Let's make the problem slightly tougher. Say you have a bunch of files that go together, such as source code for a project, or files for a website. Now if you want to keep an old version you have to archive a whole directory. Keeping many versions around by hand is inconvenient, and quickly becomes expensive. -With some computer games, a saved game really does consist of a directory full of files. These games hide this detail from the player and present a convenient interface to manage different versions of directories. +With some computer games, a saved game really does consist of a directory full of files. These games hide this detail from the player and present a convenient interface to manage different versions of this directory. Version control systems are no different. They all have nice interfaces to manage a directory of stuff. You can save the state of the directory every so often, and you can load any one of the saved states later on. Unlike most computer games, they're usually smart about conserving space. Typically, only a few files change between version to version, and not by much. Storing the differences instead of entire new copies saves room. === Distributed Control === -Now imagine a very difficult computer game. So difficult to finish that many experienced gamers all over the world decide to team up and share their saved games to try to beat it. Real-life examples of this include doing speedruns of certain games. Players specializing in different levels of the same game collaborate to produce amazing results. +Now imagine a very difficult computer game. So difficult to finish that many experienced gamers all over the world decide to team up and share their saved games to try to beat it. Speedruns are real-life examples: players specializing in different levels of the same game collaborate to produce amazing results. How would you set up a system so they can get at each other's saves easily? And upload new ones? -- 2.11.4.GIT