Skip to content

Instantly share code, notes, and snippets.

@itsmunim
Created May 23, 2016 19:48
Show Gist options
  • Save itsmunim/f939fb141e94061435004201902cb409 to your computer and use it in GitHub Desktop.
Save itsmunim/f939fb141e94061435004201902cb409 to your computer and use it in GitHub Desktop.

Some cool commands that will save your ass in need

Remove sensitive file from your git history

Usecase- There's a SSH file included in your repo; but you want to remove it. Removing it from current commit won't delete from all the history. This command will save your life.

git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA' \
--prune-empty --tag-name-filter cat -- --all

and if that's a directory, include -r:

git filter-branch --force --index-filter \
'git rm -r --cached --ignore-unmatch PATH-TO-YOUR-DIR-WITH-SENSITIVE-DATA' \
--prune-empty --tag-name-filter cat -- --all

Upload a whole directory with all it's content to remote

rsync -a DIRECTORY-PATH your_username@your_IP:/home/your_username/

This will upload the whole directory in DIRECTORY-PATH to your home/your_username/ dir of your remote address.

Search certain .extension in current dir for some text and output in a file:

find . -name "*.extension" | xargs grep -i "some text" >> output.txt

To get file names containing your text and output it into a text file:

grep -Ril "text to search" /path/to/dir >> ~/Desktop/output.txt

Recovering a deleted file which was not added to a commit after deletion

git reset HEAD <file-path>
git checkout -- <file-path>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment