Difference between revisions of "Working with Git"

From Inkscape Wiki
Jump to navigation Jump to search
Line 30: Line 30:
| class="mw-code" |bzr revert ''file'' -r ''revision''
| class="mw-code" |bzr revert ''file'' -r ''revision''
| class="mw-code" |git checkout ''commit'' -- ''file''
| class="mw-code" |git checkout ''commit'' -- ''file''
| class="mw-code" |bzr uncommit
| class="mw-code" |git reset HEAD^
| class="mw-code" |bzr uncommit<br/>...some changes...<br/>bzr commit
| class="mw-code" |bzr uncommit<br/>...some changes...<br/>bzr commit

Revision as of 16:52, 5 March 2016

This page contains an introduction to the Git distributed version control system. For now, it is mainly useful to Bazaar users, but will be updated with general Git information over time.

Cheat sheet for Bazaar users

Bazaar command Git command
bzr branch branch-url git clone repository-url directory
cd directory
git checkout branch-name
bzr checkout lp:project-name not supported
bzr update not supported
bzr pull git pull
bzr add file git add file
bzr diff git diff HEAD
bzr revert git reset --hard
bzr revert file -r revision git checkout commit -- file
bzr uncommit git reset HEAD^
bzr uncommit
...some changes...
bzr commit
...some changes...
git commit -a --amend
bzr push location git remote add remote-name location
git push remote-name branch-name
bzr commit git commit -a
bzr log -c 10 git log -n 10
bzr switch branch-url git checkout branch-name
bzr switch -b branch-url git checkout -b branch-name
bzr merge branch-url git merge branch-name
bzr shelve --all git stash
bzr unshelve change-id git stash pop

Differences from Bazaar

Here are the most important differences between Bazaar and Git:

  • Bazaar revisions are identified by sequential numbers. Git revisions (called commits in the documentation) are identified by cryptographic hashes which are strings of 40 hexadecimal numbers, though it is possible to also refer to them by a sequential number since the last tag (see git describe).
  • Bazaar is branch-oriented, while Git is repository-oriented. A repository is a collection of branches.
  • In Bazaar, you conceptually submit your work to only one place - the push branch. You can change this place at any time, but Bazaar remembers only one value for you. In Git, you can configure many remote repositories and work with code from multiple sources using a single working tree.
  • By default, each branch in Bazaar has a separate working tree, while all branches in the same Git repository share the same working tree. It's possible to make Bazaar work in the latter mode as well, but it's not very well supported.

In Bazaar, if you want to try out someone else's code, you need to create a new checkout of their branch or use bzr switch. In Git, what you do depends on where the code is located.

  • If the code to try out is in a branch in the project's main repository, you update the repository (git fetch) and then check out the branch (git checkout origin/branch-to-try-out). This creates a local branch called branch-to-try-out. (You can use a different name as well.)
  • If the code is in a different repository, you first add it as a remote repository with git remote add remote-name repository-url, fetch it with git fetch remote-name and check out the relevant branch with git checkout remote-name/branch-to-try-out.

Another difference is that in Git, you cannot directly make changes to remote branches - you must to use git push and git pull. Therefore, the Subversion-like checkout mode known from Bazaar is unsupported.