Configure name and email address

[code language=”bash”]

git config –global user.name “Vivek Bhadra” –> configuring git with the user name

git config –global user.email “vibhadra@xxxx.com” –> configuring git with user e-mail

git config –global core.autocrlf input

git config –global core.safecrlf true

[/code]

Initialize a git repo

[code language=”bash”]

git init

[/code]

Add file in the repo

[code language=”bash”]

git add hello.txt
[/code]

Commit your changes

[code language=”bash”]

git commit -m “First Commit”
[/code]

Checking status of the git repo

[code language=”bash”]

git status
[/code]

Removing a file

[code language=”bash”]

git rm –cached hello.txt –> removes the file if not already
[/code]

Discard all changes in a modified file

[code language=”bash”]

git checkout — test.c –> discards any changes made
[/code]

Unstage any staged file

[code language=”bash”]

git reset HEAD test.c –> unstages a git added file
[/code]

Checking log

[code language=”bash”]

git log –pretty=oneline –> shows git history in one line each commit

git log –grep=First –> greps the commit line

man git-log –> shows the git log man page

git log -n 2 –> shows the last two commit history

git log –pretty=format:”Commit Hash: %H, Author: %aN, Date: %aD”
[/code]

To revert back to a previous version

[code language=”bash”]

git log –> It will show the SHAsum of the previous versions.
[[/code]

For example below:

[code language=”bash”]
commit 98a31dfe2c528e4132cd8ca7af5f07e4765958aa Author: unknown Date:   Wed Jun 10 17:26:27 2015 +0100 commit message
[/code]

[code language=”bash”]
git reset  –hard
git reset –hard 98a31dfe2c528e4132cd8ca7af5f07e4765958aa
[/code]

It will set the HEAD to the specified version.

Revert Git repo to a previous commit

Temporarily switch to a different commit

[code language=”bash”]

git checkout 0d1d7fc32

If you want to move to a old commit and check it in


git checkout -b old-state 0d1d7fc32

Reverting Working Copy to Most Recent Commit

Leave a Reply