Translate

Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Monday, September 29, 2014

Git rollback latest changeset

In git to rollback the latest changeset, you do a git reset hard and specify the commit ID of the changeset before that.

For example suppose your latest commit id is fd1793a0a8366bdd48a85f7afe4fe26339f1149c. And the commit id of the previous commit is a6755301e8b283a0c7191028bb7611feff003cdd. To roll back fd1793a0a8366bdd48a85f7afe4fe26339f1149c this is what you do


git reset --hard a6755301e8b283a0c7191028bb7611feff003cdd


This points your Head to a6755301e8b283a0c7191028bb7611feff003cdd, effectively rolling back fd1793a0a8366bdd48a85f7afe4fe26339f1149c.

Thursday, March 20, 2014

Useful Git Commands

Show git global (user level) configuration information

git config --global --list  


Create global (aka user level) settings


git config --global user.name "Vivek Menon"                               

git config --global user.email "vivekmenon@dotnetanalysis.com"  

Set notepad++ as the default editor for git (works in windows 64 bit)

git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"  




Create a git repository

git init  



View Pending Changes


git status 


Add a new file (stage a new file) named play.txt to git


git add play.txt


Add all the untracked files into git in one command

git add * 

Stage all existing files that has been updated


git add -u


Commit changes to local repository


git commit -m "adding a new file"


Stage and commit in one single command


git commit -am "my comment"

Show history


git log 


(latest changes show up on the top)

(type q to exit)


Show difference between the last two commits


git diff Head~1 Head


(Head is the latest commit. Head~1 means one before the latest)



Delete a file hello.txt  


git rm hello.txt                          (stage for deletion)

git commit -m "delete hello.txt" (commit deletion)


Get back the deleted file hello.txt


do git log to see all the commits 


do git checkout <SHA-1 hash of the commit I need> hello.txt


Undo all changes that have not been staged or committed


git reset --hard