My Git Recipes

<!> Warning: be very careful before running 'git reset --hard' You will lose uncomitted changes! <!>

Accidentally committed on <master> instead of <branch>

{i} You should have committed to an existing branch but accidentally committed to master.

git branch <tmp>
git reset --hard d2bed98430712af9c5c940c5a594b8da51639eb3
git rebase --onto <branch> <master> <tmp>
git checkout <branch>
git merge <tmp>
git branch -d <tmp>

Move recent commits into <branch> instead of <master>

{i} You made a couple of commits to master but now realise they should have been split into a branch.

git branch <branch>
git reset --hard a6b4c974
git checkout <branch>

Revert an earlier commit

git revert ac14f7f40265e7a66b2927f1bbfb50cb095a3345

Track a remote branch

git checkout --track origin/<branch>

Stop tracking a remote branch

git config --unset branch.<branch>.remote
git config --unset branch.<branch>.merge
git branch -d <branch>

Delete a remote tag

git tag -d 12345
git push origin :refs/tags/12345


CategoryGit

GitTips (last edited 2011-04-04 15:08:45 by DavidKeen)