Git

From My Mnemonic Rhyme
Revision as of 10:00, 17 November 2023 by Weiss (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Cheatsheet

Remove LFS - Update current commit only

If you want to move off LFS, but are not so worried about fixing the entire git history, you can do the following;

git lfs uninstall
touch **/*
git commit -a

This will uninstall LFS support, touch every single file (so that git recognises that is has changed) then commit them all. If you like you could be more specific (ie, **/*.png for example). Note that using ** requires extended glob support enabled (shopt -s globstar on bash)

Remove LFS - Update entire history

This worked for me - but it throws lots of errors (I think I'm getting an error for every commit that a file hasn't been added to LFS in) and takes a long time (roughly 2-3 seconds per commit).

git lfs uninstall
git filter-branch -f --prune-empty --tree-filter '
  git lfs checkout
  git lfs ls-files | cut -d " " -f 3 | xargs touch
  git rm -f .gitattributes
  git lfs ls-files | cut -d " " -f 3 | git add
' --tag-name-filter cat -- --all

It uninstalls git LFS support (theoretically preventing LFS from messing with the index) then for each commit it makes sure the LFS files are checked out properly, then touches them all (so git realises they have changed), removes the settings for LFS found in .gitattributes so that when cloning it doesn't keep trying to use LFS, then adds the real file to the index.

After you do the above, you will need to do a force push. Naturally, that'll throw anyone else working on your repo into a detached head state - so doing this during a code freeze is wise. Afterwards, it's probably easiest to get everyone to do a fresh clone.

Git Submodule

git submodule add git@github.com:tobiasweede/TobisUtils ./Assets/Scripts/TobisUtils
git submodule init
git clone --recurse-submodules https://github.com/chaconinc/MainProject

Git - Repo auf Webserver verfügbar machen

Mit einem normalen clone treten probleme aus, da der master branch als bearbeitet angesehen wird.

$ mkdir /var/www/www.example.org
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f
$ chmod +x hooks/post-receive

Clone repository

git clone ssh://homaar@tobias-weiss.org:/home/homaar/java.git java

Create git repo

http://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server#_git_on_the_server

git init --bare --shared

On the Client:

git clone ssh://tobias-weiss.org/~/xyz.git
cd xyz
touch init
git add -A
git commit -m "init"
git push origin master

Reset to master

Maybe branch the work before resetting in order to preserve it:

git commit -a -m "Saving my work, just in case"
git branch my-saved-work

If all changes shall be resetet:

git fetch origin
git reset --hard origin/master

When only one single file shall be resetet:

git reset HEAD -- myFile # everything after -- is treated as filename

Git - Repo cleanen

git clean -n # show what will be deleted
git clean -xdf # rubber mallet method

Git - Lokale Files stashen

git stash
git stash show -p
git stash apply
git stash drop

view changed files

git whatchanged
# or
git diff

how to delete all commit history

git checkout --orphan newBranch
git add -A  # Add all files and commit them
git commit
git branch -D master  # Deletes the master branch
git branch -m master  # Rename the current branch to master
git push -f origin master  # Force push master branch to github
git gc --aggressive --prune=all     # remove the old files

rename branch

git branch -m new_name old_name

delete branch

#locally
git branch -d branch_name
#remote
git push <remote_name> --delete <branch_name>

push branch on remote server

git push -u origin branch_name

stash changes

git stash
git stash pop
git stash apply # keeps changes stashed
git stash drop
git stash clear # clear all stashed changes

push repo to new remote

https://stackoverflow.com/questions/20359936/import-an-existing-git-project-into-gitlab

cd existing_repo
git remote rename origin previous-hosts
git remote add gitlab git@git.hutber.com:hutber/kindred.com.git
git push -u gitlab --all
git push -u gitlab --tags

limit ram

git config --global pack.windowMemory "800m"
git config --global pack.packSizeLimit "100m"
git config --global pack.threads "1"