Zum Inhalt springen

Git: Unterschied zwischen den Versionen

Aus Computech CMS Wiki
Frederick (Diskussion | Beiträge)
Simon Zeberli (Diskussion | Beiträge)
 
(11 dazwischenliegende Versionen von 4 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
=Git=
* [[GIT Anleitung]]
* [[Git Aufräumen]]
* [[.gitconfig]]
=Git alte Einträge=
==Neues Projekt hinzufügen==
==Neues Projekt hinzufügen==
DB Aktualisieren
DB Aktualisieren
Zeile 52: Zeile 59:
=== Branch erzeugen ===
=== Branch erzeugen ===


  git branch branch_name
git branch branch_name


=== Zu einem (neuen) Branch wechseln ===
=== Zu einem (neuen) Branch wechseln ===
Zeile 64: Zeile 71:
=== Diff grafisch darstellen ===
=== Diff grafisch darstellen ===


  git difftool -y
git difftool -y


Das Diff zwischen zwei Commits:
Das Diff zwischen zwei Commits:


  git difftool -y 3c7a67 39d7a7
git difftool -y 3c7a67 39d7a7


A Diff between two branches:
A Diff between two branches:
  git difftool live dev
git difftool live dev


A Diff between two version of a file (can be commits or branches):
A Diff between two version of a file (can be commits or branches):
  git difftool mybranch master -- myfile.css
git difftool mybranch master -- myfile.css


All of the above <code>git difftool</code> commands can also be run on the command line, using '''diff''' instead of '''difftool''' like this:
All of the above <code>git difftool</code> commands can also be run on the command line, using '''diff''' instead of '''difftool''' like this:
  git '''diff''' live dev -- FileToDiff.txt
git '''diff''' live dev -- FileToDiff.txt


=== Projekt clonen ===
=== Projekt clonen ===


    git clone simon@juda:sbav.git
git clone simon@juda:sbav.git


=== Letztes Commit löschen ===
=== Letztes Commit löschen ===


  git reset --soft HEAD~1
git reset --soft HEAD~1


HEAD~1 is a shorthand for the commit before head. Alternatively you can refer to the SHA-1 of the hash you want to reset to. Note that when using --hard any changes to tracked files in the working tree since the commit before head are lost.
HEAD~1 is a shorthand for the commit before head. Alternatively you can refer to the SHA-1 of the hash you want to reset to. Note that when using --hard any changes to tracked files in the working tree since the commit before head are lost.
Zeile 93: Zeile 100:
Now if you already pushed and someone pulled which is usually my case, you can't use git reset. You can however do a git revert,
Now if you already pushed and someone pulled which is usually my case, you can't use git reset. You can however do a git revert,


  git revert HEAD
git revert HEAD


This will create a new commit that reverses everything introduced by the accidental commit.
This will create a new commit that reverses everything introduced by the accidental commit.
Zeile 103: Zeile 110:
=== Drupal Patch erzeugen ===
=== Drupal Patch erzeugen ===
Mit diesem Vorgehen, wird der Commiter in Drupal erhalten, auch wenn man nur einen Patch einreicht und der Maintainer in committed.
Mit diesem Vorgehen, wird der Commiter in Drupal erhalten, auch wenn man nur einen Patch einreicht und der Maintainer in committed.
  git format-patch f5d6d8..b539dd
git format-patch f5d6d8..b539dd


Im Issue immer folgendes schreiben:
Im Issue immer folgendes schreiben:
Zeile 116: Zeile 123:


Ausführliche Liste aller Remoteserver anzeigen:
Ausführliche Liste aller Remoteserver anzeigen:
  git remote -v
git remote -v


Einen zusätzlichen Remotserver für ein Drupal Sandbox Projekt konfigurieren:
Einen zusätzlichen Remotserver für ein Drupal Sandbox Projekt konfigurieren:
  git remote add maillog_mailwire pluess@git.drupal.org:sandbox/pluess/1179696.git
git remote add maillog_mailwire USER@git.drupal.org:sandbox/UESER/1179696.git


=== Push auf anderen Remoteserver ===
=== Push auf anderen Remoteserver ===
  git push maillog_mailwire 7.x-1.x
git push maillog_mailwire 7.x-1.x
Achtun: Es muss immer der aktuelle Branch angegeben werden. Hier also <code>7.x-1.x</code> und nicht etwa <code>master</code> wie in den Git Doks von Drupal beschrieben.
Achtun: Es muss immer der aktuelle Branch angegeben werden. Hier also <code>7.x-1.x</code> und nicht etwa <code>master</code> wie in den Git Doks von Drupal beschrieben.


Zeile 129: Zeile 136:


=== Email und Autor setzen für ein Repository ===
=== Email und Autor setzen für ein Repository ===
  git config user.email "simon.zeberli@zeberliedv.ch"
git config user.email "simon.zeberli@zeberliedv.ch"
  git config user.name "Simon"
git config user.name "Simon"


=== git-credential-store - Helper to store credentials on disk ===
=== git-credential-store - Helper to store credentials on disk ===
Zeile 139: Zeile 146:
Git provides a way that you can store you username and password to disk protected by only the filesystem permissions.
Git provides a way that you can store you username and password to disk protected by only the filesystem permissions.


Before doing a '''git push''' run:
Before doing a '''git push''' where you would need to enter your username and password run:
  git config credential.helper store
  git config credential.helper store


You will be asked for your username and password as other times but git will store your login information in less ~/.git-credentials (~ is a shell abbreviation for your home directory. ie. /home/username/).
You will be asked for your username and password as other times but git will store your login information in less ~/.git-credentials (~ is a shell abbreviation for your home directory. ie. /home/username/). This login information will be used in the future for authentication with that Git server.


To check what login information have been stored run:
To check what login information have been stored run:
Zeile 209: Zeile 216:


Ganzes production Repository auf der Kommandozeile auschecken:
Ganzes production Repository auf der Kommandozeile auschecken:
  git clone gitosis@juda:zeberliedv.git
git clone gitosis@juda:zeberliedv.git


=== Alle repositories unter cygwin auflisten ===
=== Alle repositories unter cygwin auflisten ===
Zeile 234: Zeile 241:


Als root folgendes ausführen:
Als root folgendes ausführen:
  ipkg update
ipkg update
  ipkg install gitosis
ipkg install gitosis


Die SSH Clients müssen ihren public Key hinterlegen. Zuerst auf die Synology kopieren, z.B. via einen Share dann
Die SSH Clients müssen ihren public Key hinterlegen. Zuerst auf die Synology kopieren, z.B. via einen Share dann
  sudo -H -u gitosis /opt/bin/gitosis-init < /volume1/public/id_rsa.pub
sudo -H -u gitosis /opt/bin/gitosis-init < /volume1/public/id_rsa.pub


== Konfigurieren  von gitosis ==
== Konfigurieren  von gitosis ==
Zeile 245: Zeile 252:


Clonen der Konifguration (auschecken für SVN Benutzer):
Clonen der Konifguration (auschecken für SVN Benutzer):
  git clone gitosis@paulus:gitosis-admin.git
git clone gitosis@paulus:gitosis-admin.git


Änderungen werden aktiviert, in dem sie zuerst lokal eingecheckt wird und dann auf den Server gepuscht wird. Im <code>gitosis-admin</code> Verzeichnis folgende Kommandos ausführen.
Änderungen werden aktiviert, in dem sie zuerst lokal eingecheckt wird und dann auf den Server gepuscht wird. Im <code>gitosis-admin</code> Verzeichnis folgende Kommandos ausführen.
  git commit
git commit
  git push
git push


=== Neue Benutzer anlegen ===
=== Neue Benutzer anlegen ===
Zeile 269: Zeile 276:


Danach auf dem PC ein beliebiges Verzeichnis <code>heilsarmee</code> erstellen und dort folgende Kommandos eingeben:
Danach auf dem PC ein beliebiges Verzeichnis <code>heilsarmee</code> erstellen und dort folgende Kommandos eingeben:
  git init
git init
  git remote add origin gitosis@isaak:heilsarmee.git
git remote add origin gitosis@isaak:heilsarmee.git


Jetzt können lokal irgendwelche Dateien erzeugt/geändert werden.
Jetzt können lokal irgendwelche Dateien erzeugt/geändert werden.


Dateien hinzufügen:
Dateien hinzufügen:
  git add .
git add .


Einchecken aller Änderungen:
Einchecken aller Änderungen:
  git commit -a -m "initiales Commit"
git commit -a -m "initiales Commit"


Jetzt können alle Änderungen auf den Server verschoben werden:
Jetzt können alle Änderungen auf den Server verschoben werden:
  git push origin master
git push origin master


=== Repository löschen ===
=== Repository löschen ===

Aktuelle Version vom 17. Dezember 2019, 17:30 Uhr

Git

Git alte Einträge

Neues Projekt hinzufügen

DB Aktualisieren

git clone gitosis@isaak:sbav.git

in Datei gitosis.conf

 [group ballon-zeberli]
   members = @edv
   writable = ballon-zeberli
 [repo ballon-zeberli]
   description = ballon-zeberli D7
   owner = @edv

Beim Projekt Root Ordner anwählen und mit Rechter Maustaste...

 Git Projektarchiv hier stellen

im Subordner .git die datei config

 [core]
   repositoryformatversion = 0
   filemode = false
   bare = false
   logallrefupdates = true
   symlinks = false
   ignorecase = true
   hideDotFiles = dotGitOnly
 [remote "origin"]
   url = gitosis@paulus:Projektname.git
   fetch = +refs/heads/*:refs/remotes/origin/*
   puttykeyfile = C:\\Users\\Simon\\.ssh\\id_rsa.ppk
 [branch "master"]
   remote = origin
   merge = refs/heads/master

Git Projekt Master eintragen.

Client einstellungen

in datei .gitconfig

 [core]
   repositoryformatversion = 0
   filemode = false
   bare = false
   logallrefupdates = true
   symlinks = false
   ignorecase = true
   hideDotFiles = dotGitOnly
 [remote "origin"]
   fetch = +refs/heads/*:refs/remotes/origin/*
   puttykeyfile = C:\\Users\\Simon\\.ssh\\id_rsa.ppk
 [branch "master"]
   remote = origin
   merge = refs/heads/master

Installation

Häufige Kommandos

Branch erzeugen

git branch branch_name

Zu einem (neuen) Branch wechseln

git checkout <branch_name>

Change to a new branch and create it at the same time

git checkout -b <branch_name>

Diff grafisch darstellen

git difftool -y

Das Diff zwischen zwei Commits:

git difftool -y 3c7a67 39d7a7

A Diff between two branches:

git difftool live dev

A Diff between two version of a file (can be commits or branches):

git difftool mybranch master -- myfile.css

All of the above git difftool commands can also be run on the command line, using diff instead of difftool like this:

git diff live dev -- FileToDiff.txt

Projekt clonen

git clone simon@juda:sbav.git

Letztes Commit löschen

git reset --soft HEAD~1

HEAD~1 is a shorthand for the commit before head. Alternatively you can refer to the SHA-1 of the hash you want to reset to. Note that when using --hard any changes to tracked files in the working tree since the commit before head are lost.

If you don't want to wipe out the work you have done, you can use --soft option that will delete the commit but it will leave all your changed files "Changes to be committed", as git status would put it.

Now if you already pushed and someone pulled which is usually my case, you can't use git reset. You can however do a git revert,

git revert HEAD

This will create a new commit that reverses everything introduced by the accidental commit.

Von Remote Server zurückspielen

git add -A .
git pull -v --progress "origin"

Drupal Patch erzeugen

Mit diesem Vorgehen, wird der Commiter in Drupal erhalten, auch wenn man nur einen Patch einreicht und der Maintainer in committed.

git format-patch f5d6d8..b539dd

Im Issue immer folgendes schreiben:

  The Patch is done via "git format-patch"
  If the patch is applyed, can you please use:
  git am --signoff --ignore-whitespace < integrate_with_mailwire-1125778-12.patch
  this should keep the commiter for my account :-).


Remoteserver verwalten

Einführung siehe http://progit.org/book/ch2-5.html.

Ausführliche Liste aller Remoteserver anzeigen:

git remote -v

Einen zusätzlichen Remotserver für ein Drupal Sandbox Projekt konfigurieren:

git remote add maillog_mailwire USER@git.drupal.org:sandbox/UESER/1179696.git

Push auf anderen Remoteserver

git push maillog_mailwire 7.x-1.x

Achtun: Es muss immer der aktuelle Branch angegeben werden. Hier also 7.x-1.x und nicht etwa master wie in den Git Doks von Drupal beschrieben.


Grundsätzlich sind nachfolgende Informationen auch via http://www.nslu2-linux.org/wiki/HowTo/HostingGit zu finden.

Email und Autor setzen für ein Repository

git config user.email "simon.zeberli@zeberliedv.ch"
git config user.name "Simon"

git-credential-store - Helper to store credentials on disk

git-credential-store documentation

Fehler beim Erstellen des Vorschaubildes: Datei fehlt

In a situation where multiple people are working on a git file directory it is best to not use the Bonobo Personal URL but to use the Git Repository Pfad as the remote address (add a remote with: git remote add <repository_url>).This is so that each person's commits are credited to his account. This however means that each time you push to the Bonobo repository you will be asked for your username and password.

Git provides a way that you can store you username and password to disk protected by only the filesystem permissions.

Before doing a git push where you would need to enter your username and password run:

git config credential.helper store

You will be asked for your username and password as other times but git will store your login information in less ~/.git-credentials (~ is a shell abbreviation for your home directory. ie. /home/username/). This login information will be used in the future for authentication with that Git server.

To check what login information have been stored run:

less ~/.git-credentials

To check the file permissions on your personal credential file run:

ll  ~/.git-credentials

I found that on dev01 the group was set to www-data. For added security you can change the group to your user name with:

chgrp <your_username>  ~/.git-credentials

Installation auf PC

Unter http://git-scm.com/download mysysGit herunterladen und installieren. Bei Bedarf git auch unter cygwin installieren.

TortoiseGit installieren (http://code.google.com/p/tortoisegit). Wenn TotalCommander verwendet wird, muss auf 64-Bit Systemen die 32-Bit und die 64-Bit Version installiert werden, sonst werden keine Icons angezeigt.

Beim Installieren folgende Option auswählen:

Datei:Git.jpg


Folgende SSH Einstellungen:

Fehler beim Erstellen des Vorschaubildes: Datei fehlt
Git Settings

.gitconfig Anpassen

.gitconfig Datei im Verzeichnis

  C:\Users\username\

.gitconfig

  [user]
     name = Simon Zeberli
     email = simon.zeberli@zeberliedv.ch
  [core]
     autocrlf = false
     safecrlf = false

Wenn die icons fehlen:

 http://blogs.sitepoint.com/missing-tortoisesvn-file-status-overlay-icons/

1 - Open regedit;

2 - Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers;

3 - Rename all entries that start with "Tortoise" so they start with "01_Tortoise";

4 - Kill explorer.exe/tgitcache, restart explorer.

Fehler beim Erstellen des Vorschaubildes: Datei fehlt
Git Icons

Icons aus dem Cache Löschen (Icon Cahce - Rebuild)

If one or more of your

icons are not displaying correctly, or that your icon cache is

corrupted, then you might consider rebuilding the icon cache to reset

and reload the icon images into the icon cache in Vista, Windows 7, and Windows 8.

The icon cache is located at the hidden system folder location below:

 C:\Users\%username%\AppData\Local\IconCache.db

SSH installieren

  1. SSH private Key von cygwin nach c:\Users\username\.ssh kopieren.


Ganzes production Repository auf der Kommandozeile auschecken:

git clone gitosis@juda:zeberliedv.git

Alle repositories unter cygwin auflisten

Folgenden Code ans Ende von .bashrc einfühgen:

  function repos
  {
    gitosisDir="/cygdrive/c/Users/Ernst/Source/gitosis-admin"
    awk 'BEGIN { OFS = "[] "; ORS = "\n" } 
         /repo/ {print $2}' "$gitosisDir/gitosis.conf" | sed 's/[][]//g'
  }

Danach wird mit dem Kommando repos eine Liste aller Repositories ausgegeben.


Fehlermeldung Tortoise Git commit/add

  fatal: LF would be replaced by CRLF in sites/all/modules/contrib/phone/countries.txt

Problem. Unix Datein mit nur LF wurde unter Windows erstellt/ausgepackt. Lösung: Betreffende Datei(en) unter cygwin mit unix2dos konvertieren. Danach kann normal eingecheckt werden.

Installation auf Synology

Als root folgendes ausführen:

ipkg update
ipkg install gitosis

Die SSH Clients müssen ihren public Key hinterlegen. Zuerst auf die Synology kopieren, z.B. via einen Share dann

sudo -H -u gitosis /opt/bin/gitosis-init < /volume1/public/id_rsa.pub

Konfigurieren von gitosis

Danach ist gitosis bereit und kann vom Client aus administriert werden. Das geschiet über das Verändern von Konfigurationsdateien. Wenn diese eingecheckt werden, wir die Konfiguration vorgenommen.

Clonen der Konifguration (auschecken für SVN Benutzer):

git clone gitosis@paulus:gitosis-admin.git

Änderungen werden aktiviert, in dem sie zuerst lokal eingecheckt wird und dann auf den Server gepuscht wird. Im gitosis-admin Verzeichnis folgende Kommandos ausführen.

git commit
git push

Neue Benutzer anlegen

  1. Unter gitosis-admin\keydir den public SSH Key ablegen. Filename muss dem Muster username.pub entsprechen
  2. Den Benutzer unter members in der Datei gitosis.conf in den entsprechenden Gruppen auflisten.

Neues Repository anlegen

In der Datei gitosis.conf folgendes erfassen:

  [group heilsarmee]
  members = @production
  writable = heilsarmee
  [repo heilsarmee]
  description = heilsarmee
  owner = ernst

Jetzt gitosis.conf commiten und pushen.


Danach auf dem PC ein beliebiges Verzeichnis heilsarmee erstellen und dort folgende Kommandos eingeben:

git init
git remote add origin gitosis@isaak:heilsarmee.git

Jetzt können lokal irgendwelche Dateien erzeugt/geändert werden.

Dateien hinzufügen:

git add .

Einchecken aller Änderungen:

git commit -a -m "initiales Commit"

Jetzt können alle Änderungen auf den Server verschoben werden:

git push origin master

Repository löschen

  1. Zuerst das Repository in der gitosis.conf Datei entfernen, committen und pushen.
  2. Dann auf den Server einlogen und das Repositoryverzeichnis unter /opt/share/gitosis/repositories entfernen.

Drupal Cache-Verzeichnisse von git ausschliessen

Die Datei .gitignore im Rootverzeichnis des Projektes anlegen.

Inhalt:

  sites/default/files/css
  sites/default/files/js
  sites/default/files/languages
  sites/default/files/imagecache
  sites/default/files/backup_migrate
  sites/default/files/tmp

gitosis Pfad in der Synology

Alle Daten sind auf isaak unter

  /opt/share/gitosis

abgelegt.