programming:git:start
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende ÜberarbeitungNächste ÜberarbeitungBeide Seiten der Revision | ||
programming:git:start [2019/07/23 19:25] – [lokales Repo aktualisieren] frank | programming:git:start [2023/06/08 17:06] – Externe Bearbeitung 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== GIT ====== | ||
+ | [[http:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | ===== minimaler clone ===== | ||
+ | |||
+ | < | ||
+ | git clone --depth 1 https:// | ||
+ | </ | ||
+ | |||
+ | ==== bestimmten branch ==== | ||
+ | |||
+ | < | ||
+ | git clone --depth 1 --single-branch --branch 5.4-main https:// | ||
+ | </ | ||
+ | |||
+ | mit " | ||
+ | |||
+ | $ git branch -a | ||
+ | * 5.4-main | ||
+ | remotes/ | ||
+ | |||
+ | möchte man trotzdem alle branchinformationen haben nimmt man stattdessen " | ||
+ | |||
+ | hat man nur die Sparvariante und möchte später wieder auf die anderen branches zugreifen: | ||
+ | |||
+ | git remote set-branches origin ' | ||
+ | git fetch --depth 1 | ||
+ | ===== log ===== | ||
+ | |||
+ | ==== geänderte Dateien ==== | ||
+ | |||
+ | um nur die geänderten Dateien aufzulisten: | ||
+ | |||
+ | git log --name-only --oneline | ||
+ | |||
+ | ==== Commit nach Autor suchen ==== | ||
+ | |||
+ | git log --author=" | ||
+ | |||
+ | alternativ wer es commited hat (hilfreich für Patches die via "git am" angewendet wurden) | ||
+ | |||
+ | git log --oneline --committer=frank-w | ||
+ | ==== Commits nach Text suchen ==== | ||
+ | |||
+ | in der Commit-Message | ||
+ | |||
+ | git log --grep=" | ||
+ | |||
+ | im Diff (Code-Änderung, | ||
+ | |||
+ | git log -G" | ||
+ | |||
+ | alternativ (commits finden, die den Suchstring hinzufügen/ | ||
+ | |||
+ | git log -S" | ||
+ | ==== mehrere Suchkriterien ==== | ||
+ | |||
+ | git log --all-match --grep=" | ||
+ | |||
+ | ==== alle commits eines Branches ==== | ||
+ | |||
+ | < | ||
+ | git log hnat --not main --abbrev-commit | ||
+ | </ | ||
+ | zeigt Änderungen in hnat an,welche nicht in branch main sind | ||
+ | |||
+ | ==== remote log ==== | ||
+ | |||
+ | git fetch | ||
+ | #zeigt die log des Branches master auf remote origin an | ||
+ | git log origin/ | ||
+ | #remote ermitteln (falls nicht origin): | ||
+ | git remote | ||
+ | |||
+ | ==== eigenes Format ==== | ||
+ | |||
+ | git log --pretty=format:' | ||
+ | |||
+ | ==== inklusive patch ==== | ||
+ | |||
+ | git log --oneline -p | ||
+ | ==== merges ==== | ||
+ | |||
+ | zuerst merge-commit ermitteln, z.B. so: | ||
+ | |||
+ | git log --merges | ||
+ | |||
+ | danach kann man mit diesen Commit-Hash ermitteln, welche commits dran hängen | ||
+ | |||
+ | git log --no-merges --oneline < | ||
+ | |||
+ | Beispiel als alias: | ||
+ | |||
+ | logm = !git log --no-merges --oneline $1^..$1 | ||
+ | |||
+ | will man nur die Datei-Änderungen des kompletten merges sehen, kann man das so: | ||
+ | |||
+ | git show -m < | ||
+ | ===== diff ===== | ||
+ | |||
+ | < | ||
+ | git diff COMMIT1..COMMIT2 > | ||
+ | git diff COMMIT^ COMMIT | ||
+ | # | ||
+ | git diff 4.14-main..4.9-main -- arch/ | ||
+ | |||
+ | # | ||
+ | git diff b543a94c2247bbf9e66ad9996f7d0273458faacd..bbbb5eb11e10e9fa4e0e3a620f8aa47e1e8355c4 -- . ': | ||
+ | |||
+ | #mit remote vergleichen | ||
+ | branch=$(git rev-parse --abbrev-ref HEAD) | ||
+ | git diff $branch origin/ | ||
+ | </ | ||
+ | |||
+ | ===== show ===== | ||
+ | |||
+ | git show -M HEAD^^ | ||
+ | | ||
+ | zeigt auch umbenannte Dateien an (-M = −−find-renames) | ||
+ | |||
+ | alternativ das in der git-config: | ||
+ | |||
+ | < | ||
+ | [diff] | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | ==== merge-commits ==== | ||
+ | |||
+ | git show -m 34183ddd13db | ||
+ | |||
+ | zeigt alle Änderungen durch den merge, nicht nur die Änderungen, | ||
+ | ==== bestimmte Version einer Datei ==== | ||
+ | |||
+ | git show < | ||
+ | |||
+ | man kann die Ausgabe auch an einen externen Editor (hier gedit) senden, jedoch muss man das Syntax-highlighting neu einstellen (da ja keine Datei übergeben wird an deren Endung der Dateityp erkannt wird) | ||
+ | |||
+ | git show < | ||
+ | |||
+ | alternativ kann man auch die Ausgabe in eine Temporäre Datei leiten und diese öffnen | ||
+ | |||
+ | file=< | ||
+ | git show < | ||
+ | gedit /tmp/$file | ||
+ | | ||
+ | auch committer-info zeigen | ||
+ | |||
+ | git show --format=fuller HEAD | ||
+ | ===== commit ===== | ||
+ | |||
+ | Änderungen anzeigen | ||
+ | |||
+ | git status | ||
+ | |||
+ | unversionierte Dateien hinzufügen | ||
+ | |||
+ | git add < | ||
+ | |||
+ | alles in Git übernehmen (-s=signieren) | ||
+ | |||
+ | git commit -as | ||
+ | |||
+ | nur bestimmte Dateien/ | ||
+ | |||
+ | git commit < | ||
+ | |||
+ | Nur bestimmte Teile | ||
+ | |||
+ | # | ||
+ | git add -p < | ||
+ | git commit | ||
+ | |||
+ | letzten commit überarbeiten (sollte noch nicht gepusht sein) | ||
+ | |||
+ | git add < | ||
+ | git commit --amend | ||
+ | git commit --amend --author=" | ||
+ | |||
+ | ältere commits ändern (noch nicht gepushed): | ||
+ | |||
+ | git rebase -i HEAD~X | ||
+ | # X ist ie Anzahl der Commits die man zurückgehen möchte alternativ < | ||
+ | # git rebase -i --root #wenn der erste commit geändert werden soll | ||
+ | # in die entsprechende commit-zeile gehen und nur pick in reword ändern, | ||
+ | # wenn edit statt reword: | ||
+ | git commit --amend | ||
+ | # rebase abschließen: | ||
+ | git rebase --continue | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | ===== commit in welchen tags/ | ||
+ | |||
+ | git branch --contains | ||
+ | git tag --contains | ||
+ | ===== Datei aus staging entfernen ===== | ||
+ | |||
+ | wenn versehentlich Datei/ | ||
+ | |||
+ | git reset HEAD -- Datei | ||
+ | |||
+ | ===== Datei aus vorherigen Commit entfernen ===== | ||
+ | |||
+ | wenn schon committed (und noch nicht gepushed) wurde | ||
+ | |||
+ | git reset HEAD^ .gitignore | ||
+ | git commit --amend | ||
+ | ===== tagging ===== | ||
+ | < | ||
+ | < | ||
+ | git push origin v4.16-rc1</ | ||
+ | |||
+ | < | ||
+ | |||
+ | ===== lokale Änderungen ignorieren ===== | ||
+ | |||
+ | soll eine Datei im remote-repo nicht mehr auf Änderungen überwacht werden: | ||
+ | |||
+ | git update-index --assume-unchanged [< | ||
+ | |||
+ | tracking wieder aktivieren: | ||
+ | |||
+ | git update-index --no-assume-unchanged [< | ||
+ | |||
+ | ===== push ===== | ||
+ | |||
+ | den aktuellen Branch auf das/die remote-Repo | ||
+ | |||
+ | git push | ||
+ | |||
+ | alle Branches: | ||
+ | |||
+ | git push --all origin | ||
+ | |||
+ | erzwungen (um commits entfernt zu löschen/ | ||
+ | |||
+ | #git push --force | ||
+ | git push --force-with-lease # | ||
+ | |||
+ | https:// | ||
+ | |||
+ | alternativ schauen, was sich verändert hat und rebase des lokalen trees: | ||
+ | |||
+ | git fetch #remote aktualisieren, | ||
+ | git log 5.4-main..origin/ | ||
+ | git rebase origin/ | ||
+ | ===== lokales Repo aktualisieren ===== | ||
+ | |||
+ | git fetch | ||
+ | git merge --ff-only origin/ | ||
+ | |||
+ | (funktioniert nur, wenn lokal nichts geändert wurde) | ||
+ | |||
+ | oder | ||
+ | |||
+ | git rebase --preserve-merges v4.20-rc7 | ||
+ | #neueres git (Ubuntu 20.4) | ||
+ | git rebase --rebase-merges v5.7 | ||
+ | |||
+ | (holt die Änderungen vom remote und rebased die eigenen " | ||
+ | |||
+ | alternative (aktuellen branch im losgelösten Head aktualisieren): | ||
+ | |||
+ | git rebase --onto v5.3-rc1 <erster commit>^ <letzter commit> | ||
+ | git checkout -b <neuer branch> | ||
+ | |||
+ | oder (remote mit lokal mergen inkl. merge-commit) | ||
+ | |||
+ | git pull | ||
+ | |||
+ | oder (lokalen branch mit dem remote überschreiben) | ||
+ | |||
+ | git reset --hard origin/ | ||
+ | ===== merge ===== | ||
+ | |||
+ | git merge --ff-only new-feature | ||
+ | |||
+ | https:// | ||
+ | |||
+ | möchte man immer einen merge-commit, | ||
+ | |||
+ | git merge --no-ff new-feature | ||
+ | |||
+ | den lokalen branch auf den stand des remote updaten (wenn lokal teilmenge des remote-branches) | ||
+ | |||
+ | git merge --ff-only @{upstream} | ||
+ | ===== merge-commit finden ===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | ===== revert ===== | ||
+ | |||
+ | Merge rückgängig machen | ||
+ | |||
+ | git revert -m 1 <merge commit hash> | ||
+ | |||
+ | ===== rebase ===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | git rebase -i < | ||
+ | |||
+ | History nach < | ||
+ | |||
+ | git rebase -i < | ||
+ | |||
+ | schließt commit mit ein | ||
+ | |||
+ | wurde vor dem Rebase bereits gepusht wird ein erneuter push abgewiesen (rejected), statt einem force sollte man hier folgendes verwenden, da damit zusätzliche commits (anderer Benutzer) berücksichtigt werden | ||
+ | |||
+ | git push --force-with-lease | ||
+ | |||
+ | ==== rebase als merge ==== | ||
+ | |||
+ | git checkout fix_types | ||
+ | git rebase master | ||
+ | git checkout master | ||
+ | git merge fix_typos --ff-only | ||
+ | |||
+ | https:// | ||
+ | |||
+ | als git alias (~/ | ||
+ | |||
+ | rebasefeature = "!f() { CUR=$(git rev-parse --abbrev-ref HEAD); | ||
+ | |||
+ | ==== rebase rückgängig machen ==== | ||
+ | |||
+ | git reflog | ||
+ | git reset --hard HEAD@{5} | ||
+ | |||
+ | https:// | ||
+ | ==== datei entfernen ==== | ||
+ | |||
+ | git reset HEAD^ path/ | ||
+ | git commit --amend | ||
+ | |||
+ | oder: | ||
+ | |||
+ | git reset --soft HEAD^ | ||
+ | git reset HEAD path/ | ||
+ | git commit -c ORIG_HEAD | ||
+ | |||
+ | wenn datei in späteren Commits verwendet wird, muss nun die Datei wieder separat hinzugefügt werden, sonst schlägt der rebase fehl | ||
+ | |||
+ | git co 85468fa659ac .config | ||
+ | git commit | ||
+ | |||
+ | der SHA1 ist der ursprüngliche, | ||
+ | ==== commit splitten ==== | ||
+ | |||
+ | im Rebase den jeweiligen commit mit e kennzeichnen statt pick | ||
+ | |||
+ | wenn bei dem commit angekommen: | ||
+ | |||
+ | git reset HEAD^ | ||
+ | |||
+ | um alle Datei-Änderungen dieses Commits zurückzusetzen | ||
+ | |||
+ | sollen komplette Datei-Änderungen übernommen werden, einfach via "git commit < | ||
+ | |||
+ | sollen nur bestimmte Patch-Bereiche übernommen werden mit "git add -p" arbeiten +commit | ||
+ | |||
+ | ==== Basis aktualisieren ==== | ||
+ | |||
+ | Angenommen, | ||
+ | |||
+ | git rebase master | ||
+ | |||
+ | Im feature-branch durchführen. Evtl. Vorhandene Konflikte auflösen (editieren, | ||
+ | |||
+ | ===== aufräumen ===== | ||
+ | |||
+ | git reflog expire --expire=now --all | ||
+ | git gc --aggressive --prune=now | ||
+ | |||
+ | falls das mit Fehler abbricht (out of memory): | ||
+ | |||
+ | fatal: Out of memory, realloc failed | ||
+ | error: failed to run repack | ||
+ | |||
+ | https:// | ||
+ | |||
+ | * neues ServerRepo anlegen (git init --bare) | ||
+ | * git-config erweitern | ||
+ | |||
+ | < | ||
+ | [http] | ||
+ | receivepack = true | ||
+ | [pack] | ||
+ | windowMemory = 16m | ||
+ | packSizeLimit = 56m | ||
+ | deltaCacheSize = 1 | ||
+ | threads = 1 | ||
+ | </ | ||
+ | |||
+ | * ggf. "git repack -a -d", dafür habe ich ein alias definiert< | ||
+ | cleanup = "!f() { git reflog expire --expire=now --all; git gc --aggressive --prune=now; | ||
+ | * via scp die neu gepackten (auf kleine chunks) auf den Server kopieren | ||
+ | |||
+ | < | ||
+ | scp .git/ | ||
+ | scp -r .git/ | ||
+ | </ | ||
+ | |||
+ | * Rechte auf dem Server anpassen (chmod -R user:group .;chmod -R g+w .) | ||
+ | * jetzt erst den push durchführen (ggf. mit ssh) | ||
+ | |||
+ | < | ||
+ | git push --mirror ssh:// | ||
+ | </ | ||
+ | |||
+ | git config --global core.packedGitLimit 128m | ||
+ | git config --global core.packedGitWindowSize 128 | ||
+ | |||
+ | in der gitconfig sieht das dann so aus: | ||
+ | |||
+ | [core] | ||
+ | packedGitLimit = 128m | ||
+ | packedGitWindowSize = 128 | ||
+ | |||
+ | nachdem ich irgendwann weiterhin out-of-memory Fehler bekommen hatte inklusive oom-reaper (Prozess gekillt wegen zu wenig Speicher) konnte ich das Problem mit einem zusätzlichen SWAP-Speicher (auf ssd) lösen | ||
+ | |||
+ | < | ||
+ | swapfile=/ | ||
+ | if [[ ! -e $swapfile ]];then | ||
+ | dd if=/ | ||
+ | fi | ||
+ | chmod 0600 $swapfile | ||
+ | mkswap $swapfile | ||
+ | swapon $swapfile | ||
+ | </ | ||
+ | |||
+ | Quelle: https:// | ||
+ | |||
+ | ===== filter-branch ===== | ||
+ | |||
+ | git filter-branch --tree-filter 'rm filename' | ||
+ | git filter-branch -f --tree-filter "rm -rf external/ | ||
+ | | ||
+ | git filter-branch --tree-filter "test -f \" | ||
+ | |||
+ | https:// | ||
+ | ===== whitespace-fix ===== | ||
+ | |||
+ | #make sure no patch-files are in your current directory | ||
+ | git format-patch sha1^ | ||
+ | git checkout sha1^ | ||
+ | git checkout -b branch-ws | ||
+ | git am --whitespace=fix *.patch | ||
+ | |||
+ | ===== debugging ===== | ||
+ | ==== bisect ==== | ||
+ | * https:// | ||
+ | ===== Branch ===== | ||
+ | |||
+ | ==== branch erzeugen ==== | ||
+ | |||
+ | git checkout -b < | ||
+ | git push --set-upstream origin < | ||
+ | |||
+ | ==== branch löschen ==== | ||
+ | |||
+ | entfernter Branch: | ||
+ | |||
+ | git push origin --delete < | ||
+ | |||
+ | lokal: | ||
+ | |||
+ | git branch -d < | ||
+ | |||
+ | evtl. in Schleife bei versehentlichem upload (Datei mit 1 branch pro zeile) | ||
+ | |||
+ | while read l; do git push gitlab --delete $l; done < new_branch_list.txt | ||
+ | |||
+ | ==== upstream-Verlinkung löschen ==== | ||
+ | |||
+ | git branch --unset-upstream < | ||
+ | ==== branches auflisten ==== | ||
+ | |||
+ | git branch -vv | ||
+ | |||
+ | zeigt alle branches (lokal/ | ||
+ | |||
+ | ==== Branches mit bestimmten commit finden ==== | ||
+ | |||
+ | git branch --contains < | ||
+ | ==== remote branches aktualisieren ==== | ||
+ | |||
+ | git remote update origin --prune | ||
+ | |||
+ | löscht alle Referenzen auf remote-branches, | ||
+ | |||
+ | ==== remote branch sichern ==== | ||
+ | |||
+ | bevor ein entfernter branch überschrieben / gelöscht wird, kann man ihn so in einen anderen branch (lokal) sichern | ||
+ | |||
+ | git checkout -b 5.8-rc-old origin/ | ||
+ | git branch --unset-upstream | ||
+ | ==== Datei/ | ||
+ | |||
+ | git checkout otherbranch myfile.txt | ||
+ | |||
+ | ==== commit aus anderen Branch ==== | ||
+ | |||
+ | git cherry-pick sha_hash | ||
+ | |||
+ | um eine Art Squash-merge zu machen (2+ commits in einem zusammenfassen) | ||
+ | |||
+ | git cherry-pick -n erster_commit | ||
+ | git cherry-pick -n zweiter_commit | ||
+ | git commit -a | ||
+ | |||
+ | ==== Konflikt-Markierung ==== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | < | ||
+ | <<<<<<< | ||
+ | Hello world #local | ||
+ | ======= | ||
+ | Goodbye #remote | ||
+ | >>>>>>> | ||
+ | </ | ||
+ | ==== pull-request in neuen Branch ==== | ||
+ | |||
+ | Pullrequest #13 in neuen Branch unsquashed | ||
+ | < | ||
+ | git fetch origin pull/ | ||
+ | Von https:// | ||
+ | * [neue Referenz] | ||
+ | </ | ||
+ | |||
+ | ==== Branch umbenennen ==== | ||
+ | |||
+ | <code bash> | ||
+ | OLDBR=old-name | ||
+ | NEWBR=new-name | ||
+ | # 1. Rename your local branch. | ||
+ | # If you are on the branch you want to rename: | ||
+ | git branch -m $NEWBR | ||
+ | # If you are on a different branch: | ||
+ | git branch -m $OLDBR $NEWBR | ||
+ | #2. Delete the old-name remote branch and push the new-name local branch. | ||
+ | git push origin :$OLDBR $NEWBR | ||
+ | #3. Reset the upstream branch for the new-name local branch. | ||
+ | # Switch to the branch and then: | ||
+ | git push origin -u $NEWBR | ||
+ | </ | ||
+ | |||
+ | Quelle: https:// | ||
+ | ==== Branch wechseln ==== | ||
+ | git checkout branch | ||
+ | |||
+ | ===== stash ===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | "git stash" legt Änderungen zur Seite, um trotzdem den Branch wechseln zu können | ||
+ | |||
+ | neben der quick& | ||
+ | |||
+ | git stash push -m " | ||
+ | |||
+ | einen Name vergeben | ||
+ | |||
+ | <code bash> | ||
+ | #vorhandene Stashes anzeigen | ||
+ | git stash list | ||
+ | stash@{0}: WIP on gmac: e4f9258 added missing mt7623a-rfb-emmc.dts | ||
+ | stash@{1}: WIP on main: f5b5b75 decreasing debug-level of Wifi-driver | ||
+ | |||
+ | # | ||
+ | git stash show -p stash@{1} | ||
+ | diff --git a/ | ||
+ | index d31ce3fa..19ca85c 100644 | ||
+ | --- a/ | ||
+ | +++ b/ | ||
+ | @@ -42,7 +42,7 @@ Module.symvers | ||
+ | | ||
+ | | ||
+ | *.rej | ||
+ | - | ||
+ | +u-boot/ | ||
+ | |||
+ | #stash löschen | ||
+ | git stash drop stash@{1} | ||
+ | Gelöscht stash@{1} (15af1209b06ff52e3b4ed6cf898d0e394b2da67c) | ||
+ | |||
+ | # | ||
+ | git stash apply | ||
+ | #apply + drop | ||
+ | git stash pop | ||
+ | |||
+ | #neuen branch (name=stashbranch) aus dem stash (originalposition) anlegen | ||
+ | git stash branch stashbranch stash@{0} | ||
+ | </ | ||
+ | |||
+ | ===== Mbox-Dateien ===== | ||
+ | |||
+ | häufig liegen Patches/ | ||
+ | |||
+ | git am mbox.patch | ||
+ | # | ||
+ | git am --whitespace=fix *.patch | ||
+ | |||
+ | interessant wird es, wenn ein Patch fehlschlägt. normalerweise bricht git dann ab und man muss den gesamten Patch der jeweiligen Mail manuell importieren. Ich behelfe mir mit der folgenden Vorgehensweise: | ||
+ | |||
+ | als erstes das Arbeitsverzeichnis sauber machen (git Status sollte keine Dateien/ | ||
+ | < | ||
+ | # | ||
+ | git am --reject ~/ | ||
+ | </ | ||
+ | die Ausgabe sieht etwa so aus: | ||
+ | < | ||
+ | Patch include/ | ||
+ | Wende an: arm: MediaTek: add basic support for MT7629 boards | ||
+ | Prüfe Patch arch/ | ||
+ | error: bei der Suche nach: | ||
+ | targeted at media players and tablet computers. We currently | ||
+ | support the S905 (GXBaby) 64-bit SoC. | ||
+ | |||
+ | config ARCH_LPC32XX | ||
+ | bool "NXP LPC32xx platform" | ||
+ | select CPU_ARM926EJS | ||
+ | |||
+ | error: Anwendung des Patches fehlgeschlagen: | ||
+ | Patch-Bereich #2 erfolgreich angewendet bei 1423 (-33 Zeilen versetzt) | ||
+ | </ | ||
+ | hier sieht man, dass ein Patch in arch/ | ||
+ | |||
+ | sind alle Patches angewendet, müssen die Änderungen noch übernommen werden (in das staging) via "git add < | ||
+ | |||
+ | zum Schluss wird "git am --continue" | ||
+ | |||
+ | ===== remote repos ===== | ||
+ | |||
+ | am Beispiel, wie ich einen Branch für eine neue Kernel-Version anlege | ||
+ | < | ||
+ | git checkout 4.18-main | ||
+ | git reset --hard v4.18 #back to last mainline | ||
+ | git checkout -b 4.19-rc #create new branch for new kernel | ||
+ | git remote add torvalds https:// | ||
+ | git fetch torvalds | ||
+ | git merge v4.19-rc1 | ||
+ | git push --set-upstream origin 4.19-rc | ||
+ | #add additional files | ||
+ | git checkout 4.18-main build.sh | ||
+ | git checkout 4.18-main arch/ | ||
+ | git add build.sh arch/ | ||
+ | git commit | ||
+ | git push | ||
+ | </ | ||
+ | |||
+ | ==== fremdes repo einbinden und branches nutzen ==== | ||
+ | |||
+ | < | ||
+ | git remote add vdorst https:// | ||
+ | git fetch --all | ||
+ | git log --oneline vdorst/ | ||
+ | git checkout vdorst/ | ||
+ | git checkout -b 5.0-phy #branch lokal anlegen | ||
+ | git push --set-upstream origin 5.0-phy #ins eigene remote-repo pushen | ||
+ | </ | ||
+ | ==== mehrere Push-Repos ==== | ||
+ | |||
+ | git remote set-url origin --push --add http:// | ||
+ | git remote set-url origin --push --add http:// | ||
+ | |||
+ | die git-config sieht nun so aus: | ||
+ | < | ||
+ | [remote " | ||
+ | url = http:// | ||
+ | fetch = +refs/ | ||
+ | pushurl = http:// | ||
+ | pushurl = http:// | ||
+ | </ | ||
+ | hier muss man jetzt aufpassen, da in das ursprüngliche Repo (hinter url) nicht mehr gepusht wird...dieses muss ebenfalls als push-url vorhanden sein. Es ist dabei unerheblich, | ||
+ | |||
+ | < | ||
+ | $ git remote -v | ||
+ | origin http:// | ||
+ | origin http:// | ||
+ | origin http:// | ||
+ | </ | ||
+ | |||
+ | ===== git format-patch ===== | ||
+ | |||
+ | git format-patch -vX sha1_from^..sha1_to --cover-letter | ||
+ | |||
+ | in 0000-cover-letter.patch wird dann die Beschreibung der Patch-Serie reingeschrieben | ||
+ | |||
+ | git format-patch sha1_from^..sha1_to --subject-prefix=" | ||
+ | ===== git send-email ===== | ||
+ | |||
+ | sudo apt-get install git-email | ||
+ | |||
+ | https:// | ||
+ | |||
+ | die History (changes since vX) unter die Signed-off-by mit --- getrennt | ||
+ | |||
+ | patch erzeugen (Version X von sha1 bis sha2 mit Erzeugung des Patch#0): | ||
+ | |||
+ | git format-patch -vX --cover-letter sha1^..sha2 | ||
+ | |||
+ | Patch prüfen: | ||
+ | |||
+ | scripts/ | ||
+ | |||
+ | Empfänger ermitteln: | ||
+ | |||
+ | scripts/ | ||
+ | scripts/ | ||
+ | |||
+ | hier die committer rausnehmen und in den coverletter eintragen (1 mailingliste als To und die anderen als CC) | ||
+ | |||
+ | To: linux-mediatek@lists.infradead.org | ||
+ | Cc: devicetree@vger.kernel.org, | ||
+ | linux-arm-kernel@lists.infradead.org, | ||
+ | ... | ||
+ | |||
+ | und senden | ||
+ | |||
+ | git send-email --to-cover --cc-cover v6-*.patch | ||
+ | |||
+ | http:// | ||
+ | |||
+ | falls man jemanden vergessen hat, kann man die serie nochmal so schicken (vorher im coverletter die Mailadressen entfernen und ggf. auf das Nachsenden hinweisen): | ||
+ | |||
+ | git send-email --to=linux-arm-kernel@lists.infradead.org --suppress-cc=all v6-*.patch | ||
+ | ===== Config ===== | ||
+ | |||
+ | git config --list --show-origin | ||
+ | ==== Benutzer/ | ||
+ | |||
+ | git config --global user.name "Frank Wunderlich" | ||
+ | git config --global user.email @gmx.de | ||
+ | |||
+ | |||
+ | ==== Editor ändern ==== | ||
+ | |||
+ | falls für git nicht der standard-Editor verwendet werden soll | ||
+ | |||
+ | git config --global core.editor nano | ||
+ | |||
+ | ==== Benutzername speichern ==== | ||
+ | |||
+ | in .git/config die Zeile url unter " | ||
+ | |||
+ | < | ||
+ | [remote " | ||
+ | url = https:// | ||
+ | fetch = +refs/ | ||
+ | </ | ||
+ | |||
+ | ==== Passwort-Cache ==== | ||
+ | |||
+ | Anmeldedaten die nächsten 5 Minuten speichern | ||
+ | |||
+ | git config credential.helper 'cache --timeout=300' | ||
+ | | ||
+ | === windows === | ||
+ | |||
+ | zurücksetzen von BN/PW: | ||
+ | |||
+ | rundll32.exe keymgr.dll, KRShowKeyMgr | ||
+ | |||
+ | ggf. manager neu setzen (falls openssh-dialog kommt) | ||
+ | |||
+ | git config --global credential.helper manager | ||
+ | |||
+ | ==== Alias ==== | ||
+ | git config alias.co checkout | ||
+ | git config --global alias.ren '!f() { echo \" | ||
+ | |||
+ | Beispiel Branch umbenennen: | ||
+ | |||
+ | git config --global alias.ren '!f() { git branch -m $1 $2;git push origin :$1 $2;git push origin -u $2; }; f' | ||
+ | |||
+ | alternativ: | ||
+ | |||
+ | nano .git/config | ||
+ | |||
+ | < | ||
+ | [alias] | ||
+ | st = status | ||
+ | co = checkout | ||
+ | kver = "!f() { make kernelversion; | ||
+ | ckver = "!f() { git commit -a -m \" | ||
+ | current = rev-parse --abbrev-ref HEAD | ||
+ | remote-diff = !git diff $1@{upstream}..$1@{0} | ||
+ | nextref = "!f() { git log --reverse --ancestry-path --pretty=%H $1..HEAD | head -${2:-1} | tail -1; }; f" | ||
+ | cleanup = "!f() { git reflog expire --expire=now --all; git gc --aggressive --prune=now; | ||
+ | # logone = !git log --oneline | ||
+ | logone = log --pretty=format: | ||
+ | logm = !git log --no-merges --oneline $1^..$1 #commits, welche zu einem merge-commit gehören | ||
+ | pushnew = "!git push origin $(git rev-parse --abbrev-ref HEAD);" | ||
+ | </ | ||
+ | |||
+ | ==== Farben ==== | ||
+ | |||
+ | git config --global --add color.ui true | ||
+ | #show whitespace-errors in git diff | ||
+ | git config diff.wsErrorHighlight all | ||
+ | |||
+ | ==== umbenannte Dateien ==== | ||
+ | |||
+ | git show zeigt normalerweise umbenannte Dateien als add/delete, um per default die renames anzuzeigen (wie git show -M): | ||
+ | < | ||
+ | [diff] | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | ==== bash-Integration ==== | ||
+ | |||
+ | in ~/.bashrc das vorhandene PS1 anpassen: | ||
+ | |||
+ | < | ||
+ | parseGitBranch() { | ||
+ | git rev-parse --abbrev-ref HEAD 2> /dev/null | sed -e ' | ||
+ | } | ||
+ | |||
+ | if [ " | ||
+ | PS1=' | ||
+ | else | ||
+ | PS1=' | ||
+ | fi | ||
+ | </ | ||
+ | ====== Github ====== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | ====== GIT-Server ====== | ||
+ | um pushen zu können muss auf dem " | ||
+ | |||
+ | ===== Lighttpd ===== | ||
+ | |||
+ | FIXME | ||
+ | |||
+ | aktuell gibt es bei größeren Repos (z.b. mein Kernel-repo) noch einen 400-error beim push... | ||
+ | |||
+ | <hidden Details> | ||
+ | < | ||
+ | error: RPC failed; HTTP 400 curl 22 The requested URL returned error: 400 Bad Request | ||
+ | fatal: The remote end hung up unexpectedly | ||
+ | </ | ||
+ | |||
+ | am Server: | ||
+ | |||
+ | (connections-glue.c.403) chunked data size too large -> 400 | ||
+ | |||
+ | das ist ein Bug in lighttpd, welcher zwar gefixt, aber noch nicht in debian stretch integriert ist | ||
+ | |||
+ | https:// | ||
+ | |||
+ | < | ||
+ | lighttpd -v | ||
+ | lighttpd/ | ||
+ | Build-Date: Jan 14 2017 21:07:19 | ||
+ | </ | ||
+ | evtl. auch https:// | ||
+ | |||
+ | </ | ||
+ | mit dem Lighttpd-Packet aus Buster (Nachfolger von Stretch) bricht der Transfer nicht ab, da dieses aber die libc mitzieht und man sich da leicht das ganze System zerlegt habe ich die aktuelle 1.4.51 kompiliert und in das [[https:// | ||
+ | |||
+ | < | ||
+ | <code bash> | ||
+ | #die neue Version runterladen, | ||
+ | #quellen in / | ||
+ | apt-get update | ||
+ | apt-get build-dep lighttpd | ||
+ | apt-get install wget checkinstall | ||
+ | wget https:// | ||
+ | cd / | ||
+ | sha256sum lighttpd-1.4.51.tar.gz #optional | ||
+ | tar -xf lighttpd-1.4.51.tar.gz | ||
+ | cd lighttpd-1.4.51 | ||
+ | ./configure --prefix=/ | ||
+ | make | ||
+ | |||
+ | #lief das fehlerfrei durch per checkinstall ein Packet bauen, damit es nicht lokal installiert werden muss | ||
+ | checkinstall | ||
+ | #die Frage nach der Dokumentation mit n beantworten (wenn schon bestätigt wurde kann das Verzeichnis doc-pak gelöscht werden, dann wird man erneut gefragt) | ||
+ | |||
+ | Should I create a default set of package docs? [y]: n | ||
+ | |||
+ | #beim ersten Aufruf sollte noch eine Beschreibung eingegeben werden... | ||
+ | #diese wird hier aber nicht benötigt, da später nur das usr-Verzeichnis herauskopiert wird und | ||
+ | #der Rest (modifiziert) vom alten Packet verwendet wird. | ||
+ | #Ich habe einfach nur " | ||
+ | |||
+ | #alles auf default lassen, da damit nur make install ins Packet reinläuft | ||
+ | |||
+ | #wenn fertig dann die deb nach / | ||
+ | cp *.deb ../ | ||
+ | cd ../ | ||
+ | |||
+ | # | ||
+ | root@stretch-dev:/ | ||
+ | # | ||
+ | # | ||
+ | root@stretch-dev:/ | ||
+ | root@stretch-dev:/ | ||
+ | insgesamt 20 | ||
+ | drwxr-xr-x 2 root root 4096 Jan 14 2017 DEBIAN | ||
+ | drwxr-xr-x 6 root root 4096 Jan 14 2017 etc | ||
+ | drwxr-xr-x 3 root root 4096 Jan 14 2017 lib | ||
+ | drwxr-xr-x 5 root root 4096 Jan 14 2017 usr | ||
+ | drwxr-xr-x 5 root root 4096 Jan 14 2017 var | ||
+ | #dort nun die Versionsnummer in der DEBIAN/ | ||
+ | #Version: 1.4.51-1 | ||
+ | #da auch php5-cgi nicht mehr existiert habe ich das auch angepasst (auf php-cgi) | ||
+ | |||
+ | #das neue Packet entpacken wir jetzt und kopieren den inhalt über das alte | ||
+ | dpkg-deb -R lighttpd_1.4.51-1_armhf.deb lighttpd_1.4.51_unpack | ||
+ | cp -r lighttpd_1.4.51_unpack/ | ||
+ | #zum Schluss wieder packen | ||
+ | dpkg-deb -b lighttpd_1.4.51_test lighttpd_1.4.51-2_armhf.deb | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | repo anlegen: | ||
+ | < | ||
+ | mkdir reponame | ||
+ | cd reponame | ||
+ | git init --bare | ||
+ | chown -R www-data: | ||
+ | #chmod -R g+w . | ||
+ | </ | ||
+ | |||
+ | in der config des server-repo nicht vergessen: | ||
+ | |||
+ | < | ||
+ | [http] | ||
+ | receivepack = true | ||
+ | </ | ||
+ | |||
+ | ggf. postreceive-hook für automatisches checkout: {{ : | ||
+ | |||
+ | / | ||
+ | |||
+ | < | ||
+ | # | ||
+ | server.modules += ( | ||
+ | " | ||
+ | # " | ||
+ | # " | ||
+ | " | ||
+ | |||
+ | alias.url += ( "/ | ||
+ | $HTTP[" | ||
+ | cgi.assign = ("" | ||
+ | setenv.add-environment = ( | ||
+ | " | ||
+ | " | ||
+ | ) | ||
+ | } | ||
+ | |||
+ | #anonymous read+auth write | ||
+ | # | ||
+ | # | ||
+ | #} | ||
+ | # | ||
+ | # | ||
+ | #} | ||
+ | |||
+ | #auth read+write | ||
+ | $HTTP[" | ||
+ | include " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | die git-auth.conf muss noch angelegt werden (hier ohne Funktion = unbeschränkter Zugriff): | ||
+ | |||
+ | / | ||
+ | < | ||
+ | # | ||
+ | # "/" | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # ) | ||
+ | #) | ||
+ | |||
+ | #auth backend definieren | ||
+ | </ | ||
+ | |||
+ | lighty-enable-mod git | ||
+ | |||
+ | zum Schluss noch den Webservice neustarten | ||
+ | |||
+ | service lighttpd restart | ||
+ | |||
+ | nun kann man mit folgenden Befehl ein vorhandenes Repo auf den Server spiegeln: | ||
+ | |||
+ | git push --mirror http:// | ||
+ | |||
+ | ggf. danach bei dem Repo das neue remote-repo hinzufügen | ||
+ | |||
+ | sollte nach dem Upgrade von 1.4.45 auf eine höhere Version trotz gleicher Konfig das Repo nicht mehr gefunden werden ist vermutlich in der git-config für lighttpd " | ||
+ | |||
+ | bricht git mit folgender Meldung ab: | ||
+ | |||
+ | error: RPC failed; HTTP 411 curl 22 The requested URL returned error: 411 Length Required | ||
+ | |||
+ | sollte man den post-Puffer einstellen: | ||
+ | |||
+ | git config http.postBuffer 524288000 | ||
+ | #oder global | ||
+ | git config --global http.postBuffer 524288000 | ||
+ | |||
+ | ===== automatischer Checkout bei Push ===== | ||
+ | |||
+ | hooks/ | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | TARGET="/ | ||
+ | GIT_DIR="/ | ||
+ | BRANCH=" | ||
+ | |||
+ | while read oldrev newrev ref | ||
+ | do | ||
+ | # only checking out the master (or whatever branch you would like to deploy) | ||
+ | if [[ $ref = refs/ | ||
+ | then | ||
+ | echo "Ref $ref received. Deploying ${BRANCH} branch to production..." | ||
+ | git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f | ||
+ | else | ||
+ | echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server." | ||
+ | fi | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | optional checkout filtern: | ||
+ | |||
+ | git config core.sparseCheckout true | ||
+ | |||
+ | info/ | ||
+ | |||
+ | < | ||
+ | /* | ||
+ | !external/ | ||
+ | </ | ||
+ | |||
+ | ==== automatisches build ==== | ||
+ | |||
+ | ich habe auf meinem NAS ein (sehr simples) deployment eingerichtet, | ||
+ | |||
+ | dazu muss ich natürlich erstmal die Abhängigkeiten installieren, | ||
+ | weiterhin benötigt ccache ein temp-Verzeichnis im home des Users unter dem die build.sh läuft...da dies bei mir www-data ist (home=/ | ||
+ | |||
+ | Bei mir läuft der GIT-Server in einer VM, von daher bedenkenlos möglich ;) sonst sollte zumindest der Deploy-Prozess (und die installierten Tools) in eine VM gepackt werden. | ||
+ | |||
+ | der git-hook selbst sieht dann so aus (da ich nicht nur den Master-Branch bauen möchte sind die Code-Stellen auskommentiert): | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | TARGET="/ | ||
+ | GIT_DIR="/ | ||
+ | BRANCH=" | ||
+ | |||
+ | while read oldrev newrev ref | ||
+ | do | ||
+ | # only checking out the master (or whatever branch you would like to deploy) | ||
+ | # if [[ $ref = refs/ | ||
+ | # then | ||
+ | | ||
+ | echo "Ref $ref ($oldrev => $newrev) received. Deploying | ||
+ | ${BRNCH} branch to production..." | ||
+ | mkdir -p $TARGET/ | ||
+ | git --work-tree=$TARGET/ | ||
+ | out -f $BRNCH | ||
+ | echo " | ||
+ | ( | ||
+ | echo " | ||
+ | cd $TARGET/ | ||
+ | ./build.sh importconfig | ||
+ | ./build.sh build | ||
+ | ./build.sh pack | ||
+ | #... | ||
+ | ) &> $TARGET/ | ||
+ | # else | ||
+ | # echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server." | ||
+ | # fi | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | die Befehle zum kompilieren ließen sich natürlich in eine separate Datei auslagern, die im Git selbst liegt...auch die Bedingung, welche Branches gebaut werden sollen...ich wollte es aber einfach halten ;) | ||
+ | |||
+ | das wichtigste, was fehlt ist eine Warteschlange, | ||
+ | |||
+ | if [[ " | ||
+ | if [[ " | ||
+ | |||
+ | für beide Fälle müsste der build-Prozess geparkt werden | ||
+ | ====== webbasierte Git-Tools ====== | ||
+ | ===== GITList ===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | ==== lighttpd ==== | ||
+ | |||
+ | ich habe gitlist im document_root entpackt mit name glist (damit es nicht mit /git kollidiert) | ||
+ | |||
+ | in der / | ||
+ | |||
+ | < | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | )</ | ||
+ | |||
+ | gefolgt von einem | ||
+ | |||
+ | service lighttpd restart | ||
+ | |||
+ | ==== default-branch setzen ==== | ||
+ | |||
+ | git symbolic-ref HEAD refs/ | ||
+ | |||
+ | ==== Beschreibung ==== | ||
+ | |||
+ | die Datei " | ||
+ | |||
+ | |||
+ | ===== Gitweb ==== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | / | ||
+ | |||
+ | $projectroot = "/ | ||
+ | $project_maxdepth = 1; | ||
+ | |||
+ | / | ||
+ | |||
+ | < | ||
+ | server.modules += ( " | ||
+ | # | ||
+ | alias.url += ( "/ | ||
+ | $HTTP[" | ||
+ | | ||
+ | " | ||
+ | " | ||
+ | ) | ||
+ | |||
+ | | ||
+ | } | ||
+ | </ | ||
+ | ===== git-php ===== | ||
+ | |||
+ | https:// |
programming/git/start.txt · Zuletzt geändert: 2023/09/18 13:23 von frank