Git

Nuttige Git commando's

Commando's

Branch is niet te vinden

git remote update
git branch -a

Files uploaden van lokaal naar hosting via SSH

scp -r web/sites/default/files ziekenhuisgeelbe@ssh090.webhosting.be:/data/sites/web/ziekenhuisgeelbe/production/web/sites/default

Enkele git commando's:

git pull origin master --allow-unrelated-histories
git mv showroom.png Showroom.png
git archive --remote=git@gitlab.com:brandle/little-giant-europe.git master | tar -x -C projectfolder
Verwijderde filte terugvinden in commits:
git log --full-history -- config/sync/views.view.orders.yml
De commit id kan je dan gebruiken om te bekijken in gitlab:
https://gitlab.com/brandle/maxus-be/-/commit/ce3fdf48c8961cd71e00051090fb3ddcbf1ec073

module/folder toevoegen in git waar vroeger een .git folder in zat en nu dus als 'archive' in gitlab zit:

.git folders zoeken in vendor folder en deze verwijderen

find vendor -type d -name ".git"
find vendor -type d -name ".git" -exec rm -r {} \;
find vendor -type d -name ".git" -exec rm -rf {} \;
find vendor -type d -name '.git' -exec rm -rf {} \;
find ./vendor -mindepth 2 -type d -name .git | xargs rm -rf

Je hebt een folder toegevoegd aan .gitignore die momenteel nog wel in de git zit:

git rm -r directory_to_ignore

Je hebt een file toegevoegd aan .gitignore die momenteel nog wel in de git zit:

git rm file_to_ignore

Files oplijsten die tracked zijn maar in gitignore zitten:

git config --global alias.showtrackedignored "ls-files -ic --exclude-standard"
git showtrackedignored
git rm -r -n --cached .   (bekijk wat er zou verwijderd worden)
git rm -r --cached .	  (effectief verwijderen)
git add .	          (alles terug toevoegen)
git commit -am "Remove ignored files"
git push

Oneliner: Files verwijderen die achteraf in gitignore gezet zijn doe je door even alles weg te doen en dan terug toe te voegen. Dan voegt hij niet de files toe die in gitignore zitten.

git rm -r --cached . && git add . && git commit -am "Remove ignored files"

crlf naar lf converteren

tr "\r" "\n" < /usr/bin/env > /usr/bin/env.new
git diff

Git merge conflicten behandelen

git merge development --strategy-option theirs

If solution is to accept local/our version, run:
git checkout --ours PATH/FILE

If solution is to accept remote/other-branch version, run:
git checkout --theirs PATH/FILE


If you have multiple files and you want to accept local/our version, run:
grep -lr '<<<<<<<' . | xargs git checkout --ours

If you have multiple files and you want to accept remote/other-branch version, run:
grep -lr '<<<<<<<' . | xargs git checkout --theirs

list conflicted files in git:
git diff --name-only --diff-filter=U

Git branch hernoemen

git branch -m develop development
git checkout development
git push -u origin development
git push origin --delete develop

Main branch hernoemen

git branch -m main production
git checkout production
git push -u origin production
Gitlab -> Project -> Settings -> Repository -> Default branch: wijzigen naar production
Gitlab -> Project -> Settings -> Repository -> Protected branches: main unprotecten, production protecten
git push origin --delete main

Git branch verwijderen

evt eerst in gitlab naar settings > repository > protected branches gaan en de branch niet protecten
git branch -d localBranchName
git push origin --delete remoteBranchName

Volledig teruggaan naar een specifieke commit (alle commits van erna zijn dan weg!)

git reset --hard 390006e6