7041
Kommentar:
|
10417
|
Gelöschter Text ist auf diese Art markiert. | Hinzugefügter Text ist auf diese Art markiert. |
Zeile 7: | Zeile 7: |
H\. Högl, 2012, 2015, 2018 URL: http://hhoegl.informatik.hs-augsburg.de/hhweb/doc/git-spicker.html Ich habe git in der Version 1.7.0.4 verwendet. Das Kommando |
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 |
Zeile 14: | Zeile 14: |
.. contents:: | .. contents:: Inhalt |
Zeile 16: | Zeile 17: |
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 <subcommand> --help git help <subcommand> 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 <concent>``. |
|
Zeile 22: | Zeile 91: |
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 |
|
Zeile 30: | Zeile 113: |
All possible variables are described in man page ``git config --help``. Initialisieren -------------- :: git init git add <file> git add . Dateien ignorieren durch ``.gitignore``. |
|
Zeile 40: | Zeile 138: |
Commit ------ :: git commit -a # stage all changed files (-a) git commit -a -s # sign-off commit message (-s, --signoff) git commit -a -s -m <msg> # commit message <msg> |
|
Zeile 46: | Zeile 154: |
git log --pretty=oneline -3 git log -p arch/arm/mach-lpc313x/gpiolib.c |
git log --pretty=oneline -3 # on one line, max. 3 commits, see 'git log --help' |
Zeile 59: | Zeile 165: |
git log -p | git log -p # in early days this was 'git whatchanged' |
Zeile 65: | Zeile 172: |
git show # identische mit ... git show HEAD |
git show # identisch mit git show HEAD |
Zeile 93: | Zeile 199: |
*Vorsicht*: Wenn man die beiden Argumente vertauscht, funktioniert es | *Vorsicht*: Wenn man die beiden Argumente links und rechts vom ``..`` vertauscht, funktioniert es |
Zeile 96: | Zeile 202: |
Die Ausgabe von :: git whatchanged -p src/sub1/sub1.c ist identisch mit :: git log -p arch/arm/mach-lpc313x/gpiolib.c |
|
Zeile 127: | Zeile 222: |
git push <remote> <local-branch>:<remote-branch> Entwicklungszyklus ------------------ Zwei Branches: * `master` - "mainline" oder "upstream" Entwicklung * `develop` - lokale Änderungen :: git checkout develop while (1) { do some changes git commit -a -s git format-patch master..develop git send-email <patch> } Gelegentlich:: git checkout master git pull git checkout develop git merge master # oder besser git rebase master Patch ----- |
git push <remote> <local-branch> git push <remote> <local-branch>:<remote-branch> Patches ------- |
Zeile 177: | Zeile 241: |
Man kann auch zusätzlich die Option ``-s`` (sign-off) verwenden. Mit *-o <dir>* gibt man das Verzeichnis an, in das der Patch abgelegt werden soll, wenn man nicht auf Standardausgabe ausgibt. |
Man kann auch zusätzlich die Option ``-s`` (sign-off) verwenden. Mit *-o <dir>* gibt man das Verzeichnis an, in das der Patch abgelegt werden soll, wenn man nicht auf Standardausgabe ausgibt. |
Zeile 191: | Zeile 254: |
Patch Status ausgeben: :: git apply --stat fix_empty_poster.patch Patch testen (ohne ihn anzuwenden): :: git apply --check fix_empty_poster.patch Patch anwenden: :: git apply ... # ohne sign-off # oder git am --signoff < fix_empty_poster.patch |
:: 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") |
Zeile 297: | Zeile 344: |
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 |
|
Zeile 336: | Zeile 404: |
#. Git Workflows https://www.atlassian.com/git/tutorials/comparing-workflows |
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.
Inhalt
1 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 <subcommand> --help git help <subcommand>
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 <concent>.
2 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 <your name> git config --global user.email <your e-mail> git config --global core.editor <your preferred editor, eg. vi> git config --global sendemail.smtpserver <your smtp server> git config --global sendemail.smtpserverport <your smtp server port> git config --global sendemail.smtpuser <your user name> git config --global sendemail.smtppass <your password> All possible variables are described in man page ``git config --help``.
4 Status
git status git status -uno # don't show untracked files
5 Commit
git commit -a # stage all changed files (-a) git commit -a -s # sign-off commit message (-s, --signoff) git commit -a -s -m <msg> # commit message <msg>
6 Log
git log git log --pretty=oneline -3 # on one line, max. 3 commits, see 'git log --help'
7 Ä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 <Hubert.Hoegl@hs-augsburg.de> 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.
8 Tag
In folgendem Beispiel wird dem Commit 1931ec4 (abgekürzter SHA-1) die Markierung "release-1" gegeben:
git tag release-1 1931ec4
9 Push
git push <remote> <local-branch> git push <remote> <local-branch>:<remote-branch>
10 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 <dir> 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 <your@email.com>
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.
11 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.
12 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
13 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
14 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
15 Literatur
Scott Chacon, Ben Straub, Pro Git, 2. Auflage 2014, frei lesbar unter
Git Magic
Git Immersion
A Visual Git Reference
Git Tutorial von Lars Vogel
Git from the bottom up
A Visual Git Reference
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