Skip to content

Instantly share code, notes, and snippets.

@jorgeacortes
Last active January 14, 2021 15:37
Show Gist options
  • Save jorgeacortes/2fb4329fa0571aba013cacb6b9c700f9 to your computer and use it in GitHub Desktop.
Save jorgeacortes/2fb4329fa0571aba013cacb6b9c700f9 to your computer and use it in GitHub Desktop.
Git tips, tricks and use cases

Git tips, tricks and use cases

Recover a file deleted in a old commit

Use the hash of the last commit where the file was present.

git checkout a22db0d1ddb7bc8777f43c0fda21a1c22dc75daa my_lost_file.c

Add a submodule where a folder was present before

Problem: the index is tracking the folder and gives problems when adding the submodule. Remove the folder first.

git rm my_submodule_folder
git commit -m "Deleting original folder"
git submodule add ../mysubmodule_url.git my_submodule_folder
git commit -m "Submodule added"

Use git diff outside git

You can use git as a cli diff tool for any file outside git.

git diff --no-index path/to/file1 path/to/file2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment