Skip to content
Pol Casacuberta edited this page Oct 19, 2023 · 9 revisions

Imgur Git

Go back 'x' revisions back on a file:

git checkout HEAD~x Makefile

Search for a specific string changed during all history:

git log -S'get info' -p

Go back 'x' revisions back:

git checkout HEAD~x

Go back to a previous commit and uncommit it, keeping any changes done until that commit:

git reset --soft HEAD^

Add new submodule

git submodule add URL   DIRECTORY

Submodules info

git submodule status

Update all submodules:

git submodule update --recursive --remote

Clone newly added submodules See: 1 and 2

git submodule sync
git submodule update --init --recursive

Move Submodule

git mv old/submod new/submod

View submodules differences

git diff --submodule=diff

Download only a part of a repository:

https://github.com/lodash/lodash/tree/master/testhttps://github.com/lodash/lodash/trunk/test

svn checkout https://github.com/lodash/lodash/trunk/test

Make the current commit the only commit in a git repo

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 reflog expire --all --expire=now  # remove hidden refs
git gc --aggressive --prune=all     # remove the old files
git commit -m "First commit"
git push -f origin master

Doing this didn't reduce the repo size at all

Remove file from all commits:

bfg --delete-files FILE_WITH_SENSITIVE_DATA PATH_TO_REPO
cd some-big-repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push

Remove folder from all commits:

bfg --delete-folders FOLDER_WITH_DATA PATH_TO_REPO
cd some-big-repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push

When having a problem with git commits because of size (it will uncommit everything from current branch "local")

git reset --soft origin/HEAD

Here you'll find all things i've learnt from linux thus far, enjoy!

Clone this wiki locally