Git

From HalfgeekKB
Revision as of 07:41, 31 December 2014 by Psmay (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

git is a source code management and versioning tool that differentiates itself from CVS and svn (while aligning with bzr) in being distributed: Exclusive locks aren't really a thing and most activity occurs off the network.

Undoing changes

Git is complex enough that there are several semantically distinct ways to undo work.

This flowchart by gitforteams.com gives a rundown of which one is appropriate for your situation.

vs. bzr

The single most confusing thing about git, if you're coming from bzr, is that your working copy typically encompasses multiple branches, rather than only one as normal in bzr. You list these with

git branch

and switch to one named foo with

git checkout foo

If you have a place you want your code to end up (like bzr push --remember), you set up a remote:

git remote add remotename repo-URL

Then you make it remember the "upstream branch", which is what remote and what branch to use when pushing:

git push -u remotename branch

When committing everything that's changed, you basically do

git commit -c

If there are changed files you don't want to commit, you add them (which in bzr is something you only do with files that aren't watched yet) and don't add the files to be left behind.

git add files
git commit # no -c

"git revert" doesn't do what "bzr revert" does. Do this instead:

git checkout . # Restore files as committed