{"id":2228,"date":"2018-01-01T13:43:35","date_gmt":"2018-01-01T12:43:35","guid":{"rendered":"https:\/\/bob-team.de\/wordpress\/?p=2228"},"modified":"2026-01-12T10:54:25","modified_gmt":"2026-01-12T09:54:25","slug":"repository-mit-git","status":"publish","type":"post","link":"https:\/\/bob-team.de\/wordpress\/2018\/01\/01\/repository-mit-git\/","title":{"rendered":"Repository mit Git \u2605"},"content":{"rendered":"<p>Das lokale Verzeichnis <code>c:\\develop\\my_project<\/code> soll auf dem NAS verf\u00fcgbar gemacht werden. Die Freigabe der NAS ist als Laufwerk X:\\ eingebunden.<br \/>\n<!--more--><br \/>\nIm ersten Schritt <a href=\"https:\/\/git-scm.com\/book\/de\/v1\/Git-auf-dem-Server-Git-auf-einen-Server-bekommen\">die Quelle vorbereiten<\/a>. Es wird eine Kopie vom aktuellen lokalen Repositiory ohne Arbeitsverzeichnis erzeugt. Die Kopie wird auf das NAS verschoben.<\/p>\n<pre lang=\"bash\">cd c:\\develop\r\ngit clone --bare my_project my_project.git\r\nxcopy my_project.git x:\\repros\\my_project.git \/S \/E\r\nrd my_project.git \/S \/Q<\/pre>\n<p>Abschlie\u00dfend wird das lokale Arbeitsverzeichnis mit dem neue Repositiory f\u00fcr den gemeinsamen Austausch verbunden.<\/p>\n<pre lang=\"bash\">cd c:\\develop\\my_project\r\ngit remote add origin x:\\repros\\my_project.git\r\ngit remote -v\r\ngit remote show origin<\/pre>\n<p>Nun k\u00f6nnen \u00c4nderungen auf dem NAS ver\u00f6ffentlicht werden.<\/p>\n<pre lang=\"bash\">cd c:\\develop\\my_project\r\ngit status\r\ngit commit -am \"my important comment\"\r\ngit log -1\r\ngit show-branch *master\r\ngit push origin master<\/pre>\n<p><strong>Diff<\/strong><\/p>\n<pre lang=\"bash\">\r\n# Arbeiten am Ordner\r\ngit log --oneline --pretty=format:\"%h %an - %s\" -- ordner\r\n# \u00c4nderungen pr\u00fcfen\r\ngit diff --check\r\n# Anderungen zwischen zwei Commits\r\ngit diff --oneline fe3105f 36ef02d abc.txt\r\n# \u00c4nderungen zum Parent\r\ngit show --color --pretty=format:%b XXXXXX\r\ngit diff-tree -p XXXXXX\r\ngitk ..feature-abc\r\n<\/pre>\n<p>siehe auch <a href=\"https:\/\/marklodato.github.io\/visual-git-guide\/index-de.html#diff\">Git-Referenz in Bildern<\/a><\/p>\n<p><strong>Taggen<\/strong><\/p>\n<pre lang=\"bash\">\r\ngit tag -a v0.2 -m \"Version 2020\/08, Abc, Def\"\r\ngit push origin --tags\r\ngit tag -l\r\n# Ausgabe mit Message\r\ngit tag -n1\r\n# Message \u00e4ndern\r\ngit tag eva85 eva85^{} -f -m \"Tomcat 8.5\"\r\ngit show v0.2\r\n# delete tag\r\ngit tag -d v0.2\r\ngit push origin --delete v0.2\r\n<\/pre>\n<p>siehe auch <a href=\"https:\/\/www.git-scm.com\/book\/de\/v2\/Git-Grundlagen-Taggen\">Erkl\u00e4rung<\/a> im Grundlagen-Kapitel<\/p>\n<p><strong>Alias<\/strong><\/p>\n<p>aufwendige Parameterketten zusammenfassen\/verinfachen<\/p>\n<pre lang=\"bash\">\r\n# mit Git\r\ngit config --global alias.lg \"log --all --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit\"\r\ngit lg\r\n# per Bash\r\nalias gl=\"git log --pretty=format:'%C(auto)%h%C(blue) %<|(19)%as%C(auto)%d %s'\"\r\n<\/pre>\n<p><strong>Zeilenende<\/strong><\/p>\n<p>automatische Ersetzung ausschalten (ggf. VSCode Strg+P \"Change End of Line sequence\")<\/p>\n<pre lang=\"bash\">git config --global core.autocrlf false\r\ngit add --renormalize .<\/pre>\n<p>siehe auch <a href=\"https:\/\/bob-team.de\/wordpress\/2021\/09\/05\/git-zeilenenden\/\">Git Zeilenenden<\/a>, empfohlen wird \\n<\/p>\n<p><strong>stash<\/strong><\/p>\n<pre lang=\"bash\">\r\n# Halt work on the branch feature-X\r\ngit stash\r\ngit checkout -b feature-Y origin\/main\r\n# Hack, hack, hack\u2026\r\ngit checkout feature-X or git switch -\r\ngit stash pop\r\n# Resume work on feature-X\r\n<\/pre>\n<p>siehe auch <a href=\"https:\/\/opensource.com\/article\/21\/4\/context-switching-git\">4 tips for context switching in Git<\/a><\/p>\n<pre lang=\"bash\">\r\ngit stash list\r\ngit stash show stash@{1}\r\ngit stash show -p stash@{1}\r\ngit diff stash@{1}^!\r\ngit stash apply stash@{1}\r\n<\/pre>\n<p><strong>fetch<\/strong><\/p>\n<pre lang=\"bash\">\r\n# zum Branch wechseln\r\ngit switch main\r\n# Branch aktualisieren\r\ngit fetch\r\n# \u00c4nderungen anschauen\r\ngit log --oneline origin\/main\r\ngit log HEAD..origin\/main --oneline -1\r\n# Verlauf anzeigen\r\ngit log --graph --oneline --all --decorate\r\n<\/pre>\n<p>siehe auch <a href=\"https:\/\/phoenixnap.com\/kb\/git-fetch\">Git Fetch: Definition & Examples<\/a><\/p>\n<p><strong>Branches<\/strong><\/p>\n<pre lang=\"bash\">\r\n# Branch \"develop\" erstellen und aktivieren\r\ngit checkout -b develop\r\n# alle Branches zeigen\r\ngit branch -avv\r\n# alle Branches mit Datum letzter Commit\r\ngit for-each-ref --sort=-committerdate refs\/remotes\/ --format='%(committerdate:iso8601) %(refname:short)'\r\n# Remote-Branch holen\r\ngit checkout --track origin\/newsletter\r\n# einzelne Datei aus Branch feature-xyz \u00fcbernehmen\r\ngit show feature-xyz:docs\/demo.txt\r\ngit switch master\r\ngit checkout --patch feature-xyz docs\/demo.txt\r\n# lists branches merged into master\r\ngit branch --merged master\r\ngit branch --no-merged master\r\n# Branch \"master\" \u00f6ffnen und \"develop\" einarbeiten\r\ngit checkout master\r\ngit merge develop\r\n# Branch \"develop\" lokal und im Repository l\u00f6schen\r\ngit branch -d develop\r\ngit push origin --delete develop\r\n# lokale Remote-Tracking-Branches l\u00f6schen, wenn auf Remote-Repository bereits gel\u00f6scht\r\ngit fetch --prune\r\n<\/pre>\n<p>Mit <code>for branch in `git branch -r --merged | grep -v HEAD`; do echo -e `git show --format=\"%ci %cr %an\" $branch | head -n 1` \\\\t$branch; done | sort -r<\/code> werden die Branches und ihre Autoren aufgelistet.<\/p>\n<p><strong>Commit aus Master in neuen Branch<\/strong><\/p>\n<pre lang=\"bash\">\r\n# neuen Branch anlegen (Code aktuell im Master)\r\ngit branch new-feed\r\n# einen Commit den Master zur\u00fccksetzen (statt 1 auch ander Schrittzahl m\u00f6glich)\r\ngit reset --hard HEAD~1\r\n# zum neuen Branch wechseln (geschriebener Code kommt im neuen Branch an)\r\ngit checkout new-feed\r\n<\/pre>\n<p><strong>Commit aus Master in bestehenden Branch<\/strong><\/p>\n<pre lang=\"bash\">\r\n# zum bestehenden Branch wechseln\r\ngit checkout feed-exists\r\n# alle Commits vom Master \u00fcbernehmen\r\ngit merge master\r\n# zum Master wechseln und diesen zur\u00fccksetzen (einen oder mehrere Commits)\r\ngit checkout master\r\ngit reset --hard HEAD~1\r\n<\/pre>\n<p><strong>Repo bereinigen<\/strong><\/p>\n<pre lang=\"bash\">\r\n# lokale Verweise nach Merge l\u00f6schen\r\ngit remote prune origin\r\n# interne Repr\u00e4snetation neu aufbauen\r\ngit repack\r\n# interne Repr\u00e4sentation aufr\u00e4umen\r\ngit prune-packed\r\n# Refs\/Commits ohne Zugriff \u00e4lter 2 Wochen entfernen\r\ngit gc --aggressive\r\n<\/pre>\n<p><strong>Sonstiges<\/strong><\/p>\n<pre lang=\"bash\">git config --global user.name \"Karl Mustermann\"\r\ngit config --global user.email karl@mustermann.de\r\n# git config --global --edit\r\ngit commit --amend --reset-author<\/pre>\n<pre lang=\"bash\">\r\n# SSL-Pr\u00fcfung deaktivieren\r\ngit -c http.sslVerify=false push\r\n<\/pre>\n<p>siehe <a href=\"https:\/\/stackoverflow.com\/questions\/57327608\/ssl-certificate-problem-self-signed-certificate-in-certificate-chain\">https:\/\/stackoverflow.com<\/a><\/p>\n<pre lang=\"bash\">\r\n# \u00c4nderung ohne Commit (vor Stage) r\u00fcckg\u00e4ngig machen\r\ngit checkout -- hosts.txt\r\n# lokale \u00c4nderungen zur\u00fccksetzen (-n ist Vorschau)\r\ngit fetch origin\r\ngit reset --hard origin\/master\r\ngit clean -n -f\r\n# eine Vaiable im Arbeitsverzeichnis abfragen\r\ngit config --get --bool core.bare\r\n# \u00c4nderung im Arbeitsverzeichnis r\u00fcckgangig machen\r\ngit reset hosts.txt\r\n# mit erstem Push den Upstream konfigurieren\r\n# im Anschluss nur noch: git push\r\ngit push --set-upstream origin master\r\n# Benutzer nachtr\u00e4glich \u00e4ndern\r\ngit config --global --edit\r\ngit commit --amend --reset-author\r\n# Wartung durchf\u00fchren\r\ngit count-objects -v\r\ngit fsck --full\r\ngit gc --auto\r\ngit remote set-url origin https:\/\/git.meine.de\/ich\/REPO.git\r\ngit pull origin master --allow-unrelated-histories\r\n# Dateien vom Commit\r\ngit show --pretty=\"\" --name-only 16f0\r\n# Repo durchsuchen\r\ngit rev-list --all | xargs git grep -F 'dbtool'\r\n# Repo aufr\u00e4umen\r\ngit gc --prune=now --aggressive\r\n# Commits z\u00e4hlen\r\ngit rev-list --count feature-fa\r\n# nicht versionierte Dateien auflisten\r\ngit clean -xdn\r\ngit ls-files --others\r\n<\/pre>\n<p>siehe auch: <a href=\"http:\/\/www.vogella.com\/tutorials\/EclipseGit\/article.html\">Git version control with Eclipse (EGit)<\/a>, <a href=\"https:\/\/opensource.com\/article\/18\/5\/git-branching\">A guide to Git...<\/a> oder <a href=\"https:\/\/git.wiki.kernel.org\/index.php\/GitFaq#How_to_fix_a_broken_repository.3F\">How to fix a broken repository?<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Das lokale Verzeichnis c:\\develop\\my_project soll auf dem NAS verf\u00fcgbar gemacht werden. Die Freigabe der NAS ist als Laufwerk X:\\ eingebunden.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[25,174],"class_list":["post-2228","post","type-post","status-publish","format-standard","hentry","category-software","tag-eclipse","tag-git","entry"],"_links":{"self":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts\/2228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/comments?post=2228"}],"version-history":[{"count":60,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts\/2228\/revisions"}],"predecessor-version":[{"id":4268,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts\/2228\/revisions\/4268"}],"wp:attachment":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/media?parent=2228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/categories?post=2228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/tags?post=2228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}