Git

🛠Tool
git

Recover lost file

What happened to me: I renamed a file from readme.md to README.md and edited it, then I ran git rm readme.md and the file README.md was gone for good. I made many changes and I screamed!! But his SO question saved me:

This is the magic command:

git fsck --lost-found

Thereafter take a sha value of a dangling blob entry and run git show to observe and save it, e.g.

git show 8f72c7d79f964b8279da93ca8c05bd685e892756 > restored_file.js

Recover popped stash

With git stash pop the stash is gone. With git stash apply it remains on the stash stack.

  1. Run

    Be sure gitk is installed. On OSX you can install it with brew install git-gui (not brew install gitk).

    gitk --all $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )
    1. This will open a git gui.
    2. Copy the hash of the stash.
  2. Run

    git stash apply $stash_hash

Solution taken from this SO answer.

Random

How to Use Github for Hosting Files

  • Change remote repository of local git project folder

    git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git
  • Visualize git pull/fetch/push:

git push pull graph

Source: https://stackoverflow.com/questions/1783405/how-do-i-check-out-a-remote-git-branch#answer-46057289

Discuss on TwitterImprove this article: Edit on GitHub

Discussion


Explain Programming

André Kovac builds products, creates software, teaches coding, communicates science and speaks at events.