Frequently Asked Questions about git
Contents
-
Frequently Asked Questions about git
-
Fixing mistakes
- When I "git push", I get this error message
- How do I throw away local changes (like svn revert)?
- How do I undo an '''unpushed''' commit (like if it had never happened)?
- How do I undo a '''pushed''' commit (like if it had never happened)?
- How do I remove a remote branch/tag I accidently created?
- Trying to delete a branch or tag I get "error: refname 'something' is ambiguous"
-
Miscellaneous
- How do I add a description to the git web view? What is this "blah.doap"?
- How do I get a plain text file of all GNOME repositories?
- How do I determine who pushed a certain commit?
- How do I can I get a copy of a modules doap file?
- How do I convert an anonymous clone to a non-anonymous (eponymous) clone?
-
Fixing mistakes
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">projectname</name>
<shortdesc xml:lang="en">My awesome project</shortdesc>
<homepage rdf:resource="http://example.com/projectname" />
<mailing-list rdf:resource="http://example.com/projectname/mail" />
<category rdf:resource="http://api.gnome.org/doap-extensions#other" />
<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.
Does this mean we can drop the MAINTAINER files? -- SvenHerzberg
Yes -- OlavVitters
How do I get a plain text file of all GNOME repositories?
Use the file http://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 http://git.gnome.org/log/MODULE, e.g. http://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 http://git.gnome.org/doap/MODULE, e.g. http://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.
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