Archive for the ‘Git’ Category

Git: Ignoring a folder tree except a particular sub-folder

Monday, February 7th, 2011

So, this will exclude any sub-folders form a but will include the sub-sub-sub-folder a/b/c and exclude the file a/b/c/file.xml

a/*
!b
a/b/*
!c
a/b/c/file.xml

OSX: Add autocomplete for git on Mac

Tuesday, August 17th, 2010

in the home folder (~), edit (or create) the .profile file with the following

# Set git autocompletion and PS1 integration
if [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then
  . /usr/local/git/contrib/completion/git-completion.bash
fi
GIT_PS1_SHOWDIRTYSTATE=true

if [ -f /opt/local/etc/bash_completion ]; then
    . /opt/local/etc/bash_completion
fi

PS1='[33[32m]u@h[33[00m]:[33[34m]w[33[31m]$(__git_ps1)[33[00m]$'

Source GIT Autocomplettion and enhancement

Git: remove the Git UI Loose Objects dialog popup

Monday, January 11th, 2010

Edit the from git/share/git-gui/lib/database.tcl and change

	if {$objects_current >= $object_limit} {
		set objects_current [expr {$objects_current * 250}]
		set object_limit    [expr {$object_limit    * 250}]
		if {[ask_popup ....

by:

	if {$objects_current >= $object_limit && false} {
		set objects_current [expr {$objects_current * 250}]
		set object_limit    [expr {$object_limit    * 250}]
		if {[ask_popup ....

Source: Stackoverflow: How to skip “Loose Object” popup when running ‘git gui’

Git: Merging patches git am -3 vs git apply

Friday, January 8th, 2010

Merging patches

When git-am fails to cleanly apply It will ask you to apply it yourself, to  git add the file and to run git-am --resolved.
In fact, git-am can help you a lot. When the call to git-am for a patch fails, simply run :

git-am --3way

Il will merge the file that can be automatically merge. Some files may be marked with CONFLICT and in this case, edit them to do a manual merge, and once they are fixed and run

git add $FILES_IN_CONFLICT
git-am --resolved

Merging workflow

  • I’d recommend using File -> Save As, selecting “Raw Message Source”
    as the format, then apply using:

    % git am < /path/to/saved/message
  • Consider creating a topic branch for applying the patch and then
    merging that to master. e.g.

    % git checkout -b bugfix_from_john master
    % git am < /path/to/saved/message
  • Check things out. Make minor edits if needed. You can then use “git
    add” to add in your edits and “git commit –amend” to make those
    changes part of the patch the author sent.
  • Once you’re happy:
    % git checkout master
    % git merge bugfix_from_john
    % git branch -d bugfix_from_john

Git: setup msysGit install with pageant/plink from putty

Thursday, November 19th, 2009
  1. Install msysgit
  2. Install Putty
  3. Setup Pageant
  4. Set GIT_SSH=C:Program Files (x86)PuTTYplink.exe in the windows environment
  5. Connect to the git server USING Putty (to accept the fingerprint of the server). This is only needed once.
  6. Then, you can use Git bash to connect to the ssh server

Git: Cheat Sheet

Thursday, July 2nd, 2009

Set Git push simple

git config --global push.default simple

simple means git push will push only the current branch to the one that git pull would pull from.

source

Create and Switch branch

git checkout -b my_new_branch

List local and remote branches

git branch -a

Fetch remote branch

git fetch --all
#get the remote branches
git branch -a
#fetch a remote branch as local (assuming remote branch remotes/origin/dev)
git branch dev remotes/origin/dev

Git reset -hard (good to undo merge)

git reset --hard

abandon everything since your last commit; this command can be DANGEROUS. If
merging has resulted in conflicts and you’d like to just forget about the
merge, this command will do that.

Git reset –hard HEAD^ (remove completely last commit)

git reset --hard HEAD^

Git revert last commit (this will add another commit to remove the old one)

git revert HEAD

Git clean (remove untrack files) source

git clean -f

clean directory as well:

git clean -fd

If you just want to remove ignored files, run “git clean -f -X”. If you want to remove ignored as well as non-ignored files, run “git clean -f -x”

Change filename case

git mv -f name.java Name.java

Git Abort when git am breaks

git am --abort

Git Tag (see Git tag cheat sheet)

Tag a specific branch

git tag stable-1 1b2e1d63ff

Viewing available tags is done with -l:

git tag -l

Annotated tag:

git tag -a -m "Tagging release 1.0" v1.0

Viewing tags with annotation:

git tag -l -n1

Delete a tag:

git tag -d tag_name

Push tags:

git push origin --tags

Git log with tags

git log --decorate=short

Checkout tag

git checkout -f -b [new branch name] [tag]/[sha1]

Rebase

git rebase -i HEAD~4

Git –update-index

Prevent to change a file

git update-index --assume-unchanged full/file/path.ext

Undo

git update-index --no-assume-unchanged full/file/path.ext

git ignoring changes

Display the ahead message

This will display for a specific branch.

git branch --set-upstream-to origin/my_branch

It will ensure that any time you create a new branch, you’ll automatically be able to see how many commits different it is from the branch it was created from.

git config --global branch.autosetupmerge always

source

Git log pretty with since

git log --pretty=format:"%s" TAG_UPDATE_103..TAG_UPDATE_104

Other git log

git log --graph --pretty=format:'%Cred%h -%d %s (%cr) %x09%x09%ad%x09 <%an>%Creset' --abbrev-commit --branches

git log --decorate --all --oneline --graph

See also

Git: Quick Commands, init, checkout, branch, remote add, push, pull,…

Thursday, April 16th, 2009

Git User Manual

Local repository

Create a repository:

> cd projectA
> git init

Add all the files

> git add .

Commit

> git commit

Create a public repository

Create empty bare repository (on server http://myserver.com/)

> cd /var/www/html/projectAPub
> git --bare init
> git --bare update-server-info

Make sure the hooks/post-update is enabled (see doc)
New way:

mv hooks/post-update.sample hooks/post-update

Old way:

> cd ./hooks
> chmod +x post-update

Push to public repository

Add the remote

> cd projectA
> git remote add origin ssh://username@myserver.com/var/www/html/projectAPub

Push to the public repository (origin)

> git push origin master

Get repository from Public repository

> git clone http://myserver.com/projectAPub projectA

This will create a “remote” with the default name “origin”

Get remote branch

Show remote branch(es)

> git remote show origin

Track a remote branch (fetch to make sure you have the latest remote definition)

> git fetch
> git branch --track other_branch origin/other_branch

Git: Installing Git on Centos 5

Wednesday, April 15th, 2009

Make sure you have the EPEL Repository installed in your yum repository, do the following:

> rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

Install Git with

> yum install git

You should get something like:

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 git                     x86_64     1.5.5.6-2.el5    epel              3.5 M
Installing for dependencies:
 perl-Error              noarch     1:0.17010-1.el5  epel               26 k
 perl-Git                x86_64     1.5.5.6-2.el5    epel               16 k

Transaction Summary
=============================================================================
Install      3 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 3.5 M
Is this ok [y/N]: y

Make sure the git package comes from EPEL and not RPMForge. If it comes from RPMForge, then, install yum-priorities:

> yum install priorities

Make sure that yum-priorities is enabled by editing the /etc/yum/pluginconf.d/priorities.conf file, and ensuring that it contains the following lines:

[main]
enabled=1

Add a priority=3 line in the /etc/yum.repos.d/rpmforge.repo
Add a priority=1 lines in each of the three repo sections in the /etc/yum.repos.d/elrepo.repo

Then, do the “yum install git”