Frequently Asked Questions about git

Fixing mistakes

When I "git push", I get this error message

If the error message has a URL in it, just follow it. The list of those errors is enumerated at Git/Help.

How do I throw away local changes (like svn revert)?

From http://learn.github.com/p/undoing.html

First, you have to unstage changes (ie, undoing git add <file>):

git reset HEAD <file>

You can alias this to git unstage if you like:

git config --global alias.unstage 'reset HEAD'

Then, completely throw away the unstaged changes:

git checkout -- <file>

This can also be done in a single step:

git checkout HEAD <file>

To throw away all changes in the tree, from the top-level directory (eg, equivalent to svn revert -R .):

git reset --hard HEAD

Beware though! "git reset --hard" is a VERY sharp tool. It's impossible to undo its damage, if it causes any.

How do I undo an '''unpushed''' commit (like if it had never happened)?

For the last n commits, do:

git reset HEAD~n

So if you only want to revert the last commit, do:

git reset HEAD~1

How do I undo a '''pushed''' commit (like if it had never happened)?

So if you only want to revert the last commit, do:

git reset HEAD^ --hard
git push origin -f

How do I remove a remote branch/tag I accidently created?

You can simply do:

git push origin :branchname

or for a tag:

git push origin :tagname

Sysadmins:

git push --exec=force origin :tagname

Trying to delete a branch or tag I get "error: refname 'something' is ambiguous"

This means you are trying to delete a branch (or a tag) when there is both a branch and a tag with that name.

You probably tried to delete the branch or tag with:

git push origin :something

To disambiguate the tag or branch, you needs to pass in the full ref. For branches:

git push origin :heads/something

and for tags:

git push origin :tags/something

Miscellaneous

How do I add a description to the git web view? What is this "blah.doap"?

If our cgit page told you to create a .doap file, then you need to create a reponame.doap file in your repository's toplevel directory so that cgit will find a description for your repository. DOAP files are a standard way to describe free software projects.

For example, if your project is called gnome-foo, create a gnome-foo.doap file in its toplevel directory. The cgit page uses the shortdesc tag for the Description column, so make sure you fill it in! You can steal this template:

<Project xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:foaf="http://xmlns.com/foaf/0.1/"
         xmlns:gnome="http://api.gnome.org/doap-extensions#"
         xmlns="http://usefulinc.com/ns/doap#">

  <name xml:lang="en">repository-name</name>
  <shortdesc xml:lang="en">My awesome project</shortdesc>
  <description>GNOME Shell provides core user interface functions for the GNOME 3
desktop, like switching to windows and launching applications.
GNOME Shell takes advantage of the capabilities of modern graphics
hardware and introduces innovative user interface concepts to
provide a visually attractive and easy to use experience.

Tarball releases are provided largely for distributions to build
packages. If you are interested in building GNOME Shell from source,
we would recommend building from version control using the build
script described at:

 http://live.gnome.org/GnomeShell

Not only will that give you the very latest version of this rapidly
changing project, it will be much easier than get GNOME Shell and
its dependencies to build from tarballs.</description>
  <homepage rdf:resource="https://wiki.gnome.org/Apps/CHANGE" />
  <mailing-list rdf:resource="https://mail.gnome.org/mailman/listinfo/YOUR_MAILINGLIST" />
  <download-page rdf:resource="https://download.gnome.org/sources/YOUR_PRODUCT/" />
  <bug-database rdf:resource="https://bugzilla.gnome.org/browse.cgi?product=CHANGE_TO_YOUR_BUGZILLA_PRODUCT" />
  <category rdf:resource="http://api.gnome.org/doap-extensions#deprecated" />
  <programming-language>JavaScript</programming-language>
  <programming-language>C</programming-language>

  <maintainer>
    <foaf:Person>
      <foaf:name>Rupert the Monkey</foaf:name>
      <gnome:userid>rupert</gnome:userid>
    </foaf:Person>
  </maintainer>

  <maintainer>
    <foaf:Person>
      <foaf:name>Ruperts Brother</foaf:name>
      <gnome:userid>rbrother</gnome:userid>
    </foaf:Person>
  </maintainer>
</Project>

The fragment portion of the category field's rdf:resource can be one of admin, bindings, deprecated, desktop, development, infrastructure, platform, or productivity. If your project does not belong in one of these categories, leave the category element out, and your repository will appear under the "Other" heading in cgit.

You can see the DOAP web page for more information, or original announcement about using DOAP for Gnome.

How do I get a plain text file of all GNOME repositories?

Use the file https://git.gnome.org/repositories.txt. We use this e.g. to keep the commits-list topics up to date.

How do I determine who pushed a certain commit?

git log --format=full

To always show the full log:

git config --global format.pretty full

Or use the a link like https://git.gnome.org/log/MODULE, e.g. https://git.gnome.org/log/gnome-terminal for gnome-terminal module.

How do I can I get a copy of a modules doap file?

Use the a link like https://git.gnome.org/doap/MODULE, e.g. https://git.gnome.org/doap/gnome-terminal for gnome-terminal module. Note: This will have a copy of the repositories doap file if the doap file is valid.

I'm doing my first code contribution to GNOME, when I "git push", I get "fatal: the remote end hung up unexpectedly"

To push patches direct to a code repository you must have commit access and a Git account. If you don't have a Git account (and thus not commit access) ask the maintainer in same Bugzilla report where you sent the patch to commit the patch for you, if the maintainer have not done so.

How do I convert an anonymous clone to a non-anonymous (eponymous) clone?

The easiest way in converting an anonymous clone to a clone with your account credentials is to

git config remote.origin.url ssh://MYUSERNAME@git.gnome.org/git/MODULENAME

How do I create a personal WIP branch?

git.gnome.org has a convention allowing personal WIP branches to be created, following the naming scheme:

wip/$username/$branch_name

where $username is your gnome.org nickname or username, and $branch_name is the descriptive name of the branch.

Any branch prefixed with ‘wip/’ allows force-pushes, so you may rewrite history on a WIP branch as much as you like.

The intention for allowing these branches is to standardise how people create personal branches of others’ modules. Note that you do not need the module maintainer’s permission to create such a branch — branches are cheap. Please delete personal branches once they are obsoleted or merged, however.

Personal WIP branches are effectively equivalent to forking a project on the GNOME github mirror and pushing a branch there. This is an equally acceptable way of prototyping a feature, and does not require maintainer approval, though most maintainers require patches to be submitted via Bugzilla (using git-bz) rather than a github pull request.

Similarly, maintainers may create project-wide WIP branches following the scheme:

wip/$branch_name

These do require maintainer approval to push, but since they are WIP branches, also allow force-pushes.

Git/FAQ (last edited 2015-06-26 10:05:17 by AndersJonsson)