Delete last Git commit

Posted by Dan Sosedoff on January 26, 2011

One in a while everybody makes a wrong commit. If you didnt push this commit yet you can use the following command to revert changes:

git reset --hard HEAD~1

HEAD~1 is just an alias for the commit before head. Alternatively, you can refer to the SHA-1 of the hash you want to reset to. Note that when using “–hard” any changes since the commit before head are lost. To keep changes you can use softmode “–soft” that will delete the commit but it will leave all your changed files.

In case if the commit was already pushed you can use revert command, which will create a new commit that reverses everything introduced by the accidental commit.

git revert HEAD

Snippet: Cleanup your Git repository

Posted by Dan Sosedoff on June 15, 2010

Snippet (found on net) for removing files from repository that are no longer present under your project.

$ git rm $(git ls-files -d)

For best use add it to bash alias file: ~/.bashrc or ~/.bash-aliases (under ubuntu):

alias gitclean='git rm $(git ls-files -d)'

Install Git on CentOS 5.2

Posted by Dan Sosedoff on June 28, 2009

First, we need to install all dependencies:

# yum install gettext-devel expat-devel curl-devel zlib-devel openssl-devel

Next, get the git 1.6.x sources:

# wget http://kernel.org/pub/software/scm/git/git-1.6.3.3.tar.gz

Then, unpack and cd into git sources folder and install it:

# make && make install & make clean

That`s it, now you`ll have git system ready to go.