Git
Starting out
Notify git of your identity and ID:
git config --global user.email "yourname@yoursite.yourdomain" git config --global user.name yourID
To avoid entering git userID and password:
git config --global credential.helper 'cache --timeout 7200'
To address the usual "^M" problem when switching between Linux and Windows environments
$ git config --global core.autocrlf true # Remove everything from the index $ git rm --cached -r . # Re-add all the deleted files to the index # You should get lots of messages like: "warning: CRLF will be replaced by LF in <file>." $ git diff --cached --name-only -z | xargs -0 git add # Commit $ git commit -m "Fix CRLF"
(Also see https://stackoverflow.com/questions/1889559/git-diff-to-ignore-m)
Restoring Files
First, see this link:
https://stackoverflow.com/questions/953481/find-and-restore-a-deleted-file-in-a-git-repository
A recipe that may work well:
git log --diff-filter=D --summary # finds deleted files git checkout $commit~1 filename # where "$commit" stands for the actual commit name (a long string)
In the above, it's best to operate from the top level directory of the project and use path relative to that. Also, you may want to "git add" the restored files and commit them to make it permanent.
If you want to get a specific previous revision of a file, just capture the stdout of the following command:
git show $REV:$FILE
...and rename the output as you see fit.
Undoing a commit
See:
https://sethrobertson.github.io/GitFixUm/fixup.html
If you want to reverse your latest commit to the HEAD:
git reset --hard HEAD
To remove two last commits:
git reset --hard HEAD~2
gitHub quirks
Sometimes a cloned repo will end up in a state where you can't push local content. Things you might want to try:
git remote set-url origin https://buddhasystem@github.com/DUNE/dqmconfig.git
And in case it was not annoying enough, if you see something like "can't open display" this may help:
unset SSH_ASKPASS