7791
Kommentar:
|
7856
|
Gelöschter Text ist auf diese Art markiert. | Hinzugefügter Text ist auf diese Art markiert. |
Zeile 77: | Zeile 77: |
git log --pretty=oneline -3 # on one line, max. 3 commits | git log --pretty=oneline -3 # on one line, max. 3 commits, see 'git log --help' |
Zeile 88: | Zeile 88: |
git log -p # frueher war das 'git whatchanged' | git log -p # in early days this was 'git whatchanged' |
Zeile 145: | Zeile 145: |
git push <remote> <local-branch>:<remote-branch> | git push <remote> <local-branch> git push <remote> <local-branch>:<remote-branch> |
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 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``.
3 Status
git status git status -uno # don't show untracked files
4 Log
git log git log --pretty=oneline -3 # on one line, max. 3 commits, see 'git log --help'
5 Ä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.
6 Tag
In folgendem Beispiel wird dem Commit 1931ec4 (abgekürzter SHA-1) die Markierung "release-1" gegeben:
git tag release-1 1931ec4
7 Push
git push <remote> <local-branch> git push <remote> <local-branch>:<remote-branch>
8 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
9 Patch
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
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
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.
10 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.
11 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
12 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
13 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