#format rst #language de Git Spicker =========== H\. Högl, 2012, 2015, 2018, 2019 URL: http://hhoegl.informatik.hs-augsburg.de/hhwiki/Git Ich habe git in der Version 2.17.1 verwendet. Das Kommando ``git --version`` gibt die Version aus. .. contents:: Inhalt .. sectnum:: Hilfe ----- Wenn man auf der Kommandozeile ``git`` eingibt, dann bekommt man u.a. eine gruppierte Übersicht zu den verfügbaren Subkommandos:: start a working area (see also: git help tutorial) clone Clone a repository into a new directory init Create an empty Git repository or reinitialize an existing one work on the current change (see also: git help everyday) add Add file contents to the index mv Move or rename a file, a directory, or a symlink reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index examine the history and state (see also: git help revisions) bisect Use binary search to find the commit that introduced a bug grep Print lines matching a pattern log Show commit logs show Show various types of objects status Show the working tree status grow, mark and tweak your common history branch List, create, or delete branches checkout Switch branches or restore working tree files commit Record changes to the repository diff Show changes between commits, commit and working tree, etc merge Join two or more development histories together rebase Reapply commits on top of another base tip tag Create, list, delete or verify a tag object signed with GPG collaborate (see also: git help workflows) fetch Download objects and refs from another repository pull Fetch from and integrate with another repository or a local branch push Update remote refs along with associated objects Zu allen Git Subkommandos gibt es Manual-Seiten. Diese bekommt man immer durch folgende Eingaben :: git --help git help Mit ``git help -a`` bekommt man eine Liste aller *Subkommandos*. Mit ``git help -g`` bekommt man einen Liste der *Git Guides*, auch *Concept Guides* genannt:: attributes Defining attributes per path everyday Everyday Git With 20 Commands Or So glossary A Git glossary ignore Specifies intentionally untracked files to ignore modules Defining submodule properties revisions Specifying revisions and ranges for Git tutorial A tutorial introduction to Git (for version 1.5.1 or newer) workflows An overview of recommended workflows with Git Einen Guide betrachtet man mit ``git help ``. Konfigurieren ------------- :: git config -l # show configuration variables defined in .git/config user.email=Hubert.Hoegl@hs-augsburg.de user.name=Hubert Hoegl push.default=simple core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.srv.url=ssh://hhoegl.informatik.hs-augsburg.de:2222/data/tgit/00repos/oss remote.srv.fetch=+refs/heads/master:refs/remotes/srv/master branch.master.remote=srv branch.master.merge=refs/heads/master # set some variables git config --global user.name git config --global user.email git config --global core.editor git config --global sendemail.smtpserver git config --global sendemail.smtpserverport git config --global sendemail.smtpuser git config --global sendemail.smtppass All possible variables are described in man page ``git config --help``. Initialisieren -------------- :: git init git add git add . Dateien ignorieren durch ``.gitignore``. Status ------ :: git status git status -uno # don't show untracked files Commit ------ :: git commit -a # stage all changed files (-a) git commit -a -s # sign-off commit message (-s, --signoff) git commit -a -s -m # commit message Log ---- :: git log git log --pretty=oneline -3 # on one line, max. 3 commits, see 'git log --help' Änderungen herausfinden ----------------------- Alle Änderungen von allen Commits im Patch-Format auf die Standardausgabe ausgeben: :: git log -p # in early days this was 'git whatchanged' Aktuelle Änderungen des letzten Commit :: git show # identisch mit git show HEAD Änderungen von einem bestimmten Commit ausgeben: :: git show 1931ec4d8592cd5599771dd65f1a5d0dfc7237cb Man kann die lange ID des Commit (ein SHA-1 Hash) auch abkürzen, solange sie eindeutig ist. Im konkreten Beispiel würde auch folgendes funktionieren:: git show 1931ec4 Welche Commits sind noch nicht mit ``push`` auf das entfernte Repository übertragen worden? :: git log remotes/origin/hhoegl..hhoegl commit 9330d1aba6a7a9d64795e4af906c1a995e5eddd9 Author: Hubert Hoegl Date: Thu Apr 26 10:13:38 2012 +0200 GPIO > 15 aktiviert *Vorsicht*: Wenn man die beiden Argumente links und rechts vom ``..`` vertauscht, funktioniert es nicht. Tag --- In folgendem Beispiel wird dem Commit 1931ec4 (abgekürzter SHA-1) die Markierung "release-1" gegeben: :: git tag release-1 1931ec4 Branch ------ :: git branch # create new branch... git checkout # and switch to the new branch oder in einem Schritt:: git checkout -b Merge ----- :: git checkout master # switch to "receiving" branch git pull # fetch and merge changes git merge # merge into master Push ----- :: git push git push : Patches ------- Normalerweise erstellt git für jeden Commit einen eigenen Patch. Einen *einzigen* Patch für alle Commits zwischen dem aktuellen Entwicklungsbranch und dem Branch `master` erstellt man so: :: git format-patch master --stdout > my.patch Man kann auch zusätzlich die Option ``-s`` (sign-off) verwenden. Mit *-o * gibt man das Verzeichnis an, in das der Patch abgelegt werden soll, wenn man nicht auf Standardausgabe ausgibt. In der Schreibweise :: git format-patch master..develop werden zwei Branches angegeben, zwischen denen die Patches erzeugt werden. **Patch anwenden** :: git apply --check my.patch # just check, don't apply git apply my.patch # apply w/o sign-off git apply --stat my.patch # print patch status git am --signoff < my.patch # apply with sign-off ("apply mailbox") Letzteres Kommando führt zu einer "Signed-off-by" Meldung bei ``git log``. Die sieht so aus:: Signed-off-by: Your Name Man kann auch noch die Option ``--whitespace=strip`` angeben. Der Name und die Email-Adresse können in den Umgebungsvariablen GIT_COMMITTER_NAME und GIT_COMMITTER_EMAIL abgelegt werden. Commit Meldungen nachträglich ändern ------------------------------------ Die Spitze ("tip") des aktuellen Zweiges ("branch") ändern. :: git commit --amend -m "New commit message" Änderungen, die weiter zurück liegen, werden mit `git rebase` gemacht. Möchte man den vorletzten Commit bearbeiten, muss man sich mit folgendem Kommando die letzten zwei Commits besorgen: :: git rebase -i HEAD~2 Danach landet man in einem Editor mit folgendem Text: :: pick f58e28b Ein paar Aenderungen in .config pick b71ec7a GPIO > 15 aktiviert # Rebase 4ad3a02..b71ec7a onto 4ad3a02 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. Wenn man die zwei Zeilen mit "pick" löscht und aus dem Editor herausgeht, dann erscheint "Nothing to do". Wenn man eine der Zeilen von "pick" auf "reword" ändert, dann kann man die Commit Meldung abändern. Archivierung ------------ :: git archive -l git archive --prefix=glunz/ HEAD | gzip >glunz-20080628.tar.gz git archive --prefix=glunz/ v0.1 | gzip >glunz-0.1.tar.gz Grafische Werkzeuge ------------------- Git GUIs * `git-cola `_ (meine Empfehlung) * smartgit https://www.syntevo.com/smartgit/ * git-eye https://www.collab.net/downloads/giteye * GitKraken https://www.gitkraken.com * git-gui http://repo.or.cz/w/git-gui.git (Tk) * tig - text-mode interface for Git * tgit - Tortoise git (nur Windows) * GitX (Mac OS X) Repository browser * gitk * gitg Umgebungsvariable ----------------- Eine Liste aller Variablen findet man in ``man git``. Hier sind einige gebräuchliche angegeben: * PREFIX * HOME * GIT_EXEC_PATH * GIT_PAGER * GIT_EDITOR * GIT_DIR * GIT_WORK_TREE * GIT_AUTHOR_NAME * GIT_AUTHOR_EMAIL * GIT_AUTHOR_DATE * GIT_COMMITTER_NAME * GIT_COMMITTER_EMAIL * GIT_COMMITTER_DATE Literatur --------- 1. Scott Chacon, Ben Straub, Pro Git, 2. Auflage 2014, frei lesbar unter http://git-scm.com/book/en/v2 #. Git Magic http://www-cs-students.stanford.edu/~blynn/gitmagic #. Git Immersion http://gitimmersion.com/ #. A Visual Git Reference http://marklodato.github.io/visual-git-guide/index-en.html #. Git Tutorial von Lars Vogel http://www.vogella.com/tutorials/Git/article.html #. Git from the bottom up http://ftp.newartisans.com/pub/git.from.bottom.up.pdf #. A Visual Git Reference http://marklodato.github.com/visual-git-guide/index-en.html #. Intro to Distributed Version Control (Illustrated) http://betterexplained.com/articles/intro-to-distributed-version-control-illustrated #. Peter Bell; Brent Beer, Introducing Github, O'Reilly 2014.  http://proquest.tech.safaribooksonline.de/book/databases/content-management-systems/978149194980 #. Git Workflows https://www.atlassian.com/git/tutorials/comparing-workflows .. vim: et sw=4 ts=4