Difference between revisions of "Git"

From Organic Design wiki
(See also: Duplicate a Git repository)
(useful git commands)
Line 12: Line 12:
  
 
If a repository is cloned, git tracks the '''master''' which is the latest commit on the remote repository, as well as the '''origin/master''' which is the last '''known''' commit from the source sourced repository. This is updated if your remote changes are pushed back to the repository you cloned from.  
 
If a repository is cloned, git tracks the '''master''' which is the latest commit on the remote repository, as well as the '''origin/master''' which is the last '''known''' commit from the source sourced repository. This is updated if your remote changes are pushed back to the repository you cloned from.  
 
We could use Git to maintain article revisions for the [[Extension:P2P.php|P2P MediaWiki Extension]].
 
  
 
== Using Git to update Wikimedia extensions ==
 
== Using Git to update Wikimedia extensions ==
Line 21: Line 19:
 
{{code|<pre>git checkout 6854b712f200a833220c156a2499f502317c20c1</pre>}}
 
{{code|<pre>git checkout 6854b712f200a833220c156a2499f502317c20c1</pre>}}
  
== Git GUI ==
+
== Reverting a working copy ==
[http://www.kernel.org/pub/software/scm/git/docs/git-gui.html Git Gui] is a Tcl/Tk based graphical user interface to Git. git-gui focuses on allowing users to make changes to their repository by making new commits, amending existing ones, creating branches, performing local merges, and fetching/pushing to remote repositories. Unlike gitk(1), git-gui focuses on commit generation and single file annotation, and does not show project history. It does however supply menu actions to start a gitk session from within git-gui.
+
{{code|<bash>git reset --hard <branch/tag/rev></bash>}}
 
 
== Git clone ==
 
If you are cloning from some elses repository you should generally always do this on the same machine. The reason is that unless the file permissions are set accordingly you will not be able to push changes back to their version of the repository, so within a machine you can clone some elses repo, but between machines you should generally clone your own copy of a repo so that you '''can''' push and pull changes between machines. It may be that the users mask could be altered from '''022''' to '''011''', in shared repo directories but this needs testing.
 
 
 
{{code|<bash>
 
## Probably the first thing you want to do, clone a repository
 
git clone git@ssh.github.com:[user]/[project]
 
 
 
## Locally commit something
 
touch foo
 
git add foo
 
## commit changes to local repository
 
git commit -m "test"
 
## Push changes back to git-hub
 
git push
 
</bash>}}
 
 
 
== Git pull ==
 
This is the equivalent of ''svn update'', but sometimes it complains of local changes that need committing first (even though nothing has been changed locally!). Here's the best way to reset it so the ''git pull'' will work again.
 
{{code|<bash>
 
git reset --hard HEAD
 
git pull
 
</bash>}}
 
 
 
== Time to go back... ==
 
Reverting what you’ve done since last commit is easy.
 
{{code|<bash>
 
$ git diff .bashrc | patch -p1 -u -R
 
</bash>}}
 
 
 
And for svn
 
{{code|<bash>
 
$ svn diff .bashrc | patch –p0 –u -R
 
</bash>}}
 
The idiom of sourcecode management is “commit often”.  You can always role back any number of steps at a time. Rolling back half a step is difficult though.
 
  
{{code|<bash>
+
== Updating just a single file ==
$ cat <<'EOF' > ~/bin/git_revert
+
{{code|<bash>git fetch</bash>}}
#!/bin/bash
 
  
git diff "$*" | patch -p1 -u -R
+
followed by
EOF
 
</bash>}}
 
  
===.gitconfig===
+
{{code|<bash>git checkout origin/master -- path/to/file</bash>}}
The ''.gitconfig'' file is either in ''/etc'', or $HOME, and is configurable either directly through the git commands;
 
{{code|<bash>
 
git config --global doe@foobar.com
 
git config --global user.email "doe@foobar.com"
 
## Pretty colours
 
git config --global color.branch "auto"
 
</bash>}}
 
Or directly by editing the file [[.gitconfig|$HOME/.gitconfig]].
 
{{code|<bash>
 
[user]
 
        name = John Doe
 
        email = jdoe@foobar.com
 
</bash>}}
 
  
 
== Links to Setting up Git Servers ==
 
== Links to Setting up Git Servers ==

Revision as of 18:01, 5 March 2015

Broom icon.svg The content of this article requires cleaning up to meet OD's quality standards. Check the wiki best practices for guidelines on improving article and categorisation quality.

Git is a distributed revision control / software code management project created by Linus Torvalds, initially for the Linux kernel development.

Git's design was inspired by BitKeeper and Monotone. Git was originally designed only as a low-level engine that others could use to write front ends such as Cogito or StGIT. However, the core Git project has since become a complete revision control system that is usable directly. Several high-profile software projects now use Git for revision control, most notably the Linux kernel, X.org Server, One Laptop per Child (OLPC) core development, and the Ruby on Rails web framework.

Git differs from systems such as CVS, or SVN in that the database is maintained beside the working filesystem on peers. Each peer is easily sync'ed to any other by using push/pull or fetch. In subversion you use three main directory structures;

  • trunk
  • branch
  • tag

In git the trunk is equivalent to HEAD, and is a sha1sum to the latest commit. Branches are used to fork development from the HEAD if for example bug fixing is required. A tag in git is just a named sha1sum commit which is effectilvely a static reference to a particular snapshot of code.

If a repository is cloned, git tracks the master which is the latest commit on the remote repository, as well as the origin/master which is the last known commit from the source sourced repository. This is updated if your remote changes are pushed back to the repository you cloned from.

Using Git to update Wikimedia extensions

git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/<EXT>.git

This clones the entire repo including all revisions to your local system. To change the local directory structure to a specific revision, use checkout with the required commit hash, e.g.

git checkout 6854b712f200a833220c156a2499f502317c20c1

Reverting a working copy

<bash>git reset --hard <branch/tag/rev></bash>

Updating just a single file

<bash>git fetch</bash>

followed by


<bash>git checkout origin/master -- path/to/file</bash>

Links to Setting up Git Servers

See also