Git: Unterschied zwischen den Versionen

Aus Vosp.info
Wechseln zu:Navigation, Suche
(Zu älterer Version zurückkehren)
 
(29 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
 
== repository anlegen ==
 
== repository anlegen ==
  mkdir neurepository.git
+
<source lang="bash">
  cd neurepository.git
+
mkdir neurepository.git
  git --bare init
+
cd neurepository.git
 +
git --bare init
 +
 
 +
# Dateirechte werden ignoriert
 +
git config core.fileMode false
 +
 
 +
 
 +
</source>
 +
  ''Initialized empty Git repository in /var/www/git/neurepository.git/''
 +
 
 +
== repository holen ==
 +
<source lang="bash">
 +
git clone git+ssh://user@1.2.3.4:22/var/www/git/neurepository.git
 +
</source>
 +
''Cloning into 'neurepository'...''
 +
''warning: You appear to have cloned an empty repository.''
 +
 
 +
 
 +
'''beim holen eines initialisierten bare Repository'''
 +
<source lang="bash">
 +
echo README > README
 +
git add README
 +
git commit -a -m 'README'
 +
</source>
 +
''[master (root-commit) 7301f81] README''
 +
''1 file changed, 1 insertion(+)''
 +
''create mode 100644 README''
 +
<source lang="bash">
 +
git push origin master    # muss auf jeden Fall beim leeren bare Repository gemacht werden
 +
</source>
 +
''Counting objects: 3, done.''
 +
''Writing objects: 100% (3/3), 213 bytes, done.''
 +
''Total 3 (delta 0), reused 0 (delta 0)''
 +
''To git+ssh://user@1.2.3.4:22/var/www/git/neurepository.git''
 +
  ''* [new branch]      master -> master''
 +
 
 +
=== git branch vom server holen ===
 +
<source lang="bash">
 +
git checkout --track origin/****
 +
 
 +
</source>
 +
* https://git-scm.com/book/de/v1/Git-Branching-Externe-Branches
 +
 
 +
<source lang=bash>
 +
git clone https://git.typo3.org/Packages/TYPO3.CMS.git
 +
cd TYPO3.CMS/
 +
git fetch
 +
git checkout -b  8.7.2 8.7.2
 +
</source>
 +
 
 +
=== git tag vom server holen ===
 +
<source lang="bash">
 +
git checkout -b  tags/TYPO3_7-6-0
 +
</source>
 +
== Fehlermeldungen ==
 +
 
 +
=== To dir.git ! [remote rejected] master -> master (branch is currently checked out) error: Fehler beim Versenden einiger Referenzen nach ===
 +
'''Fehler'''
 +
<source lang="bash">
 +
git push origin master
 +
</source>
 +
remote: error: refusing to update checked out branch: refs/heads/master
 +
remote: error: By default, updating the current branch in a non-bare repository
 +
remote: error: is denied, because it will make the index and work tree inconsistent
 +
remote: error: with what you pushed, and will require 'git reset --hard' to match
 +
remote: error: the work tree to HEAD.
 +
remote: error:
 +
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
 +
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
 +
remote: error: its current branch; however, this is not recommended unless you
 +
remote: error: arranged to update its work tree to match what you pushed in some
 +
remote: error: other way.
 +
remote: error:
 +
remote: error: To squelch this message and still keep the default behaviour, set
 +
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
 +
To git.....git
 +
  ! [remote rejected] master -> master (branch is currently checked out)
 +
error: Fehler beim Versenden einiger Referenzen nach 'git....git'
 +
 
 +
'''Lösung'''
 +
 
 +
auf dem Server Schreibrechte kontrollieren, darf der Benutzer überhaupt push'en!
 +
<source lang="bash">
 +
git config receive.denyCurrentBranch ignore
 +
</source>
 +
* http://stackoverflow.com/questions/3221859/cannot-push-into-git-repository
 +
=== error: insufficient permission for adding an object to repository database ./objects ===
 +
'''Fehler'''
 +
<source lang="bash">
 +
git push origin master
 +
</source>
 +
''error: insufficient permission for adding an object to repository database ./objects''
 +
''fatal: failed to write object''
 +
''error: unpack failed: unpack-objects abnormal exit''
 +
 
 +
'''Lösung'''
 +
 
 +
auf dem Server Schreibrechte kontrollieren, darf der Benutzer überhaupt push'en!
 +
<source lang="bash">
 +
chgrp git neurepository.git/ -R
 +
chmod ug+rw neurepository.git/ -R
 +
</source>
 +
=== error: failed to push some refs to 'git+ssh://user@1.2.3.4:22/var/www/git/neurepository.git' ===
 +
'''Fehler'''
 +
<source lang="bash">
 +
git push
 +
</source>
 +
''No refs in common and none specified; doing nothing.''
 +
''Perhaps you should specify a branch such as 'master'.''
 +
''fatal: The remote end hung up unexpectedly''
 +
''error: failed to push some refs to 'git+ssh://user@1.2.3.4:22/var/www/git/neurepository.git'''
 +
'''Lösung'''
 +
<source lang="bash">
 +
git push origin master
 +
</source>
 +
 
 +
== notizen ==
 +
<source lang="bash">
 +
echo README > README
 +
git add README
 +
git commit -a -m 'README'
 +
git log
 +
git branch
 +
</source>
 +
 
 +
 
 +
== Zu älterer Version zurückkehren ==
 +
Die letzen Änderungen waren nicht so gut und mensch möchte mit einer älteren, guten Version weiter machen.
 +
<source lang="bash">
 +
# es sollte committet UND gepusht werden, ansonsten kann der reset nicht wieder gepullt also rückgängig gemacht werden und der zwischenstand commit ist futsch!!!!!!!
 +
git commit -a -m 'zwischenstand'
 +
git push
 +
 
 +
 
 +
#
 +
git log
 +
 
 +
# mit folgenden ist mensch bei dem punkt wie zu <sha1> zeiten
 +
git reset --hard <sha1>
 +
git reset --hard HEAD~1
 +
 
 +
# mit pull ist mensch raz faz wieder in der gegenwart, natürlich sollte mensch nichts verändert haben, sonst ist es wie zurück in die zukunft .. die gegenwart ist verändert
 +
#  Achtung funktioniert natürlich nur wenn vorher der zwischenstand gepusht worden ist
 +
git pull
 +
 
 +
</source>
 +
 
 +
* http://iblog.ikarius.net/index.php/2012/06/11/den-letzten-git-commit-loschen/  -- reset hard und soft
 +
 
 +
=== letzte commit ===
 +
muss noch mal kontrolliert werden !!!
 +
<source lang="bash">
 +
git rm -r .
 +
git commit  -a -m 'deleted'
 +
git checkout HEAD~1
 +
</source>
 +
http://stackoverflow.com/questions/3380805/checkout-old-commit-and-make-it-a-new-commit
 +
 
 +
== Grafische Programme ==
 +
 
 +
git-cola
 +
apt-get install git-cola
 +
 
 +
Git Cola unterstützt viele Funktionen.
 +
 
 +
 
 +
== Bash skripte ==
 +
 
 +
=== mvServerGitToLocal.sh: sync server .git zum local .git ===
 +
* beide Dateien liegen im selben Verzeichnis
 +
* idealer Weise in einem Verzeichnis, welches gleich aufgebaut ist auf dem server wie local
 +
 
 +
'''mvServerGitToLocal_config.sh'''
 +
<source lang=bash>
 +
#! /bin/bash
 +
 
 +
ncsshhosturi='root@typo3devhost.netz.coop:/var/www/subdomain.netz.coop/'
 +
 
 +
 
 +
nchostgitarray[0]='typo3conf/ext/ancext1/'
 +
nchostgitarray[1]='typo3conf/ext/ancext2/'
 +
nchostgitarray[2]='typo3conf/ext/ancext3/'
 +
nchostgitarray[3]='typo3conf/ext/ancext4/'
 +
nchostgitarray[4]='typo3conf/ext/ancext5/'
 +
nchostgitarray[5]='typo3conf/ext/'
 +
nchostgitarray[6]='typo3conf'
 +
</source>
 +
 
 +
 
 +
'''mvServerGitToLocal.sh'''
 +
<source lang=bash>
 +
#! /bin/bash
 +
#
 +
# - beide Dateien liegen im selben Verzeichnis
 +
# - idealer Weise in einem Verzeichnis, welches gleich aufgebaut ist auf dem server wie local
 +
#
 +
# @param boolean $1 - ob gesynct werden soll
 +
 
 +
source ./mvServerGitToLocal_config.sh
 +
 
 +
locationOfScript=$(dirname "$(readlink -e "$0")")
 +
 
 +
for ncpath in "${nchostgitarray[@]}"
 +
do
 +
if [ -d $ncpath/.git ]
 +
then
 +
echo ""
 +
echo "#"
 +
echo -e '\E[37;44m'"\033[1m# sync git $ncpath\033[0m"
 +
if [ $1 ]
 +
then
 +
echo "# rsync --delete --stats -haze ssh $ncsshhosturi$ncpath.git $ncpath/ "
 +
rsync --delete --stats -haze ssh $ncsshhosturi$ncpath.git $ncpath/
 +
fi
 +
cd $ncpath
 +
echo "# git log -1"
 +
git log -1
 +
git diff
 +
cd $locationOfScript
 +
fi
 +
done
 +
</source>
 +
 
 +
 
 +
== Commit aus History löschen ==
 +
<source lang=bash>
 +
git git rebase --onto 625388537797f5c2323ea944ae14339f3bad8ddb^ 625388537797f5c2323ea944ae14339f3bad8ddb
 +
git push  --force
 +
</source>
 +
 
 +
== Patch erstellen ==
 +
<source lang=bash>
 +
# Anzahl z.B. 1 seit dem 625388537797f
 +
git format-patch -1 625388537797f
 +
#oder vom Head
 +
git format-patch -1 HEAD
 +
 
 +
#seit commit 625388537797f
 +
git format-patch 625388537797f
 +
#und einspielen:
 +
git am 0001-msg.patch
 +
# oder alle
 +
git am *.patch
 +
 
 +
 
 +
 
 +
 
 +
</source>
 +
 
 +
 
 +
 
 +
== Datei Temporär ignorieren ==
 +
<source lang=bash>
 +
# Temporär ignorieren
 +
git update-index --assume-unchanged .htaccess
 +
 
 +
# wieder verfügbar machen
 +
git update-index --no-assume-unchanged .htaccess
 +
</source>
 +
== Quellen ==
 +
* [http://wiki.weinimo.de/Git-Hilfen Git-Hilfen - deutsch]

Aktuelle Version vom 15. Januar 2019, 16:09 Uhr

repository anlegen

mkdir neurepository.git
cd neurepository.git
git --bare init

# Dateirechte werden ignoriert
git config core.fileMode false
Initialized empty Git repository in /var/www/git/neurepository.git/

repository holen

git clone git+ssh://user@1.2.3.4:22/var/www/git/neurepository.git
Cloning into 'neurepository'...
warning: You appear to have cloned an empty repository.


beim holen eines initialisierten bare Repository

 echo README > README
 git add README
 git commit -a -m 'README'
[master (root-commit) 7301f81] README
1 file changed, 1 insertion(+)
create mode 100644 README
 git push origin master    # muss auf jeden Fall beim leeren bare Repository gemacht werden
Counting objects: 3, done.
Writing objects: 100% (3/3), 213 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git+ssh://user@1.2.3.4:22/var/www/git/neurepository.git
* [new branch]      master -> master

git branch vom server holen

git checkout --track origin/****
git clone https://git.typo3.org/Packages/TYPO3.CMS.git
cd TYPO3.CMS/
git fetch
git checkout -b  8.7.2 8.7.2

git tag vom server holen

git checkout -b  tags/TYPO3_7-6-0

Fehlermeldungen

To dir.git ! [remote rejected] master -> master (branch is currently checked out) error: Fehler beim Versenden einiger Referenzen nach

Fehler

 git push origin master
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To git.....git
 ! [remote rejected] master -> master (branch is currently checked out)
error: Fehler beim Versenden einiger Referenzen nach 'git....git'

Lösung

auf dem Server Schreibrechte kontrollieren, darf der Benutzer überhaupt push'en!

git config receive.denyCurrentBranch ignore

error: insufficient permission for adding an object to repository database ./objects

Fehler

 git push origin master
error: insufficient permission for adding an object to repository database ./objects
fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit

Lösung

auf dem Server Schreibrechte kontrollieren, darf der Benutzer überhaupt push'en!

 chgrp git neurepository.git/ -R
 chmod ug+rw neurepository.git/ -R

error: failed to push some refs to 'git+ssh://user@1.2.3.4:22/var/www/git/neurepository.git'

Fehler

 git push
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'git+ssh://user@1.2.3.4:22/var/www/git/neurepository.git'

Lösung

 git push origin master

notizen

 echo README > README
 git add README
 git commit -a -m 'README'
 git log
 git branch


Zu älterer Version zurückkehren

Die letzen Änderungen waren nicht so gut und mensch möchte mit einer älteren, guten Version weiter machen.

# es sollte committet UND gepusht werden, ansonsten kann der reset nicht wieder gepullt also rückgängig gemacht werden und der zwischenstand commit ist futsch!!!!!!!
git commit -a -m 'zwischenstand'
git push


#
git log

# mit folgenden ist mensch bei dem punkt wie zu <sha1> zeiten
git reset --hard <sha1>
git reset --hard HEAD~1

# mit pull ist mensch raz faz wieder in der gegenwart, natürlich sollte mensch nichts verändert haben, sonst ist es wie zurück in die zukunft .. die gegenwart ist verändert
#   Achtung funktioniert natürlich nur wenn vorher der zwischenstand gepusht worden ist
git pull

letzte commit

muss noch mal kontrolliert werden !!!

git rm -r .
git commit  -a -m 'deleted'
git checkout HEAD~1

http://stackoverflow.com/questions/3380805/checkout-old-commit-and-make-it-a-new-commit

Grafische Programme

git-cola

apt-get install git-cola 
Git Cola unterstützt viele Funktionen. 


Bash skripte

mvServerGitToLocal.sh: sync server .git zum local .git

  • beide Dateien liegen im selben Verzeichnis
  • idealer Weise in einem Verzeichnis, welches gleich aufgebaut ist auf dem server wie local

mvServerGitToLocal_config.sh

#! /bin/bash

ncsshhosturi='root@typo3devhost.netz.coop:/var/www/subdomain.netz.coop/'


nchostgitarray[0]='typo3conf/ext/ancext1/'
nchostgitarray[1]='typo3conf/ext/ancext2/'
nchostgitarray[2]='typo3conf/ext/ancext3/'
nchostgitarray[3]='typo3conf/ext/ancext4/'
nchostgitarray[4]='typo3conf/ext/ancext5/'
nchostgitarray[5]='typo3conf/ext/'
nchostgitarray[6]='typo3conf'


mvServerGitToLocal.sh

#! /bin/bash
#
# - beide Dateien liegen im selben Verzeichnis
# - idealer Weise in einem Verzeichnis, welches gleich aufgebaut ist auf dem server wie local
#
# @param boolean $1 - ob gesynct werden soll

source ./mvServerGitToLocal_config.sh

locationOfScript=$(dirname "$(readlink -e "$0")")

for ncpath in "${nchostgitarray[@]}"
do
	if [ -d $ncpath/.git ]
	then
		echo ""
		echo "#"
		echo -e '\E[37;44m'"\033[1m# sync git $ncpath\033[0m"
		if [ $1 ]
		then
			echo "# rsync --delete --stats -haze ssh $ncsshhosturi$ncpath.git $ncpath/ "
			rsync --delete --stats -haze ssh $ncsshhosturi$ncpath.git $ncpath/
		fi
		cd $ncpath
		echo "# git log -1"
		git log -1
		git diff
		cd $locationOfScript
	fi
done


Commit aus History löschen

git  git rebase --onto 625388537797f5c2323ea944ae14339f3bad8ddb^ 625388537797f5c2323ea944ae14339f3bad8ddb
 git push  --force

Patch erstellen

# Anzahl z.B. 1 seit dem 625388537797f
git format-patch -1 625388537797f
#oder vom Head
git format-patch -1 HEAD

#seit commit 625388537797f
git format-patch 625388537797f
#und einspielen:
git am 0001-msg.patch
# oder alle
git am *.patch


Datei Temporär ignorieren

# Temporär ignorieren
git update-index --assume-unchanged .htaccess

# wieder verfügbar machen
git update-index --no-assume-unchanged .htaccess

Quellen