Posts tagged: git

git checkout a specific commit

To checkout a specific commit in git

git checkout -b <new branch name> <SHA1 commit number>

For example

git checkout -b release-3.16.3-022cbb7552e 022cbb7552e

git bisect – Isolating a broken commit

git bisect – Isolating a broken commit

git bisect start

# Mark current commit as bad
git bisect bad

# Set the first good commit - the start of the bisect commit set
git bisect good some-commit-here

.. compile and run tests ...

# Mark the current commit as either bad or good
# Git will automatically apply the next subset of commits if bad
git bisect good / bad

# Done bisecting - we found the bad commit
git bisect reset

Git and GUIs

Git comes with a simple GUI tool – gitk – that does for many.

GitX is a nice OS X-only GUI

git commands – Specifying a default editor

To specify a default editor for git commands (that require one) In ~/.gitconfig

[core]
  editor = "vi"

To specify Texmate

[core]
  editor = "mate -w"

Git stash syntax

If you want to refer to a specific stash from a list similar to the one below:

stash@{0}: On release-3.10.0-captcha_service: Captcha service integration
stash@{1}: On release-3.11.0: 3.11 login cookie and widget support changes
stash@{2}: On master: 3.11 Walkthrough

use the full name of the stash.

git stash apply stash@{2}

If not specified, the default is stash@{0}

Useful git techniques

(From github setup)

Global setup:

git config –global user.email someone@email.com

Next steps:

mkdir ruby19-norubygems
cd ruby19-norubygems
git init
touch README
git add README
git commit -m ‘first commit’
git remote add origin git@github.com:tflynn/ruby19-norubygems.git
git push origin master

Existing Git Repo?

cd existing_git_repo
git remote add origin git@github.com:tflynn/ruby19-norubygems.git
git push origin master

When you’re done:

To push a new branch to an (established) remote repository

git push origin <new branch name>

Create a remote branch from a local branch

git push origin release-3.10.0:refs/heads/release-3.10.0

To pull a new remote branch into an existing repository

To obtain the new code (in an existing repository)

git checkout –track -b release-3.12.0 origin/release-3.12.0
git pull

To pull from a remote repository branch to a local branch (for the same codebase … )

  • Make sure both branches are up to date with respect to the parent repository
  • Make sure the local branch you want to update is the active branch
  • git pull <remote repo – SSH reference with fully qualified path> <remote branch>

Other handy tips

To move or rename a git branch

git branch -m old_branch new_branch

To delete a (local) git branch

git branch -D branch_name

To delete a remote git branch

 git push origin :heads/branch_name

Subversion => Git migration

To import a Subversion repository into a (new) Git repository

mkdir the_new_git_repo
cd the_new_git_repo
git svn init -t tags -b branches -T trunk the_old_repo_svn_url
git svn fetch

Git – Useful tricks

To pull from a branch on another machine

  1. Create a branch on your local machine – git branch -a [new branch name] [existing (origin) branch]
  2. Switch to new branch
  3. git pull some_user@somehost:[absolute pathname to repo] [branch on remote machine]

GitHub – Create a new repository

GitHub

Global setup:

git config –global user.email github.10.tracyflynn@spamgourmet.com

Next steps:

mkdir testme
cd testme
git init
touch README
git add README
git commit -m ‘first commit’
git remote add origin git@github.com:tflynn/testme.git
git push origin master

Existing Git Repo?

cd existing_git_repo
git remote add origin git@github.com:tflynn/testme.git
git push origin master

When you’re done:

Continue

WordPress Themes