Thursday, February 26, 2015

Remove Files From Repository but Keep Them Locally

git rm --cached -r somedir will stage the deletion of the directory, but doesn't touch anything on disk.
You should then add somedir/ to your .gitignore file so that git doesn't try and add it back.

Tuesday, February 17, 2015

Git: How to revert to a previous commit

This depends a lot on what you mean by "revert".

Temporarily switch to a different commit

If you want to temporarily go back to it, fool around, then come back to where you are, all you have to do is check out the desired commit:
# This will detach your HEAD, that is, leave you with no branch checked out:
git checkout 0d1d7fc32
Or if you want to make commits while you're there, go ahead and make a new branch while you're at it:
git checkout -b old-state 0d1d7fc32

Hard delete unpublished commits

If, on the other hand, you want to really get rid of everything you've done since then, there are two possibilities. One, if you haven't published any of these commits, simply reset:
# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32

# Alternatively, if there's work to keep:
git stash
git reset --hard 0d1d7fc32
git stash pop
# This saves the modifications, then reapplies that patch after resetting.
# You could get merge conflicts, if you've modified things which were
# changed since the commit you reset to.

Undo published commits with new commits

On the other hand, if you've published the work, you probably don't want to reset the branch, since that's effectively rewriting history. In that case, you could indeed revert the commits. With Git, revert has a very specific meaning: create a commit with the reverse patch to cancel it out. This way you don't rewrite any history.
# This will create three separate revert commits:
git revert a867b4af 25eee4ca 0766c053

# It also takes ranges. This will revert the last two commits:
git revert HEAD~2..HEAD

# Reverting a merge commit
git revert -m 1 <merge_commit_sha>

# To get just one, you could use `rebase -i` to squash them afterwards
# Or, you could do it manually (be sure to do this at top level of the repo)
# get your index and work tree into the desired state, without changing HEAD:
git checkout 0d1d7fc32 .

# Then commit. Be sure and write a good message describing what you just did
git commit

Monday, February 16, 2015

NANO

Ctrl

^O
save contents without exiting (you will be prompted for a file to save to)
^X
exit nano (you will be prompted to save your file if you haven't)
^T
when saving a file, opens a browser that allows you to select a file name from a list of files and directories

SVN command

 svn add * --force

Wednesday, February 11, 2015

GIT Reconcile Detached HEAD with Master/origin

git branch temp
git checkout temp
git branch -f master temp
git checkout master
git branch -d temp
git push -f origin master