Thursday 24 September 2015

Part 3 - git skim : Undo Changes (Checkout/revert/reset/clean)

git chekcout:
Suppose you modified a file. Now you want to bring the file back to its original state.
git checkout <file> 
Checkout previous version of file
git checkout <commit> <file>

git revert (undo public commit):
Revert some existing commit.
Create new commit that undoes all of the changes made in , then apply it to the current branch.
git revert <commit>

git reset (undo local changes):
Use it for unstaging changes or uncommitting a series of snapshots.Remove the specified file from the staging area, but leave the working directory unchanged.
git reset <file>
Reset staging area to match most recent commit. It leaves the working directory unchanged.
git reset
Reset the staging area to match to the commit. It leaves the working directory unchanged.
git reset <commit>
Reset both staging and working area to match most recent commit.
git reset --hard
Reset both staging and working area to match <commit>
git reset --hard <commit>

git clean:
Removes untracked files from working directory
Show which files are going to be removed without actually removing them.
git clean --dry-run
Remove untracked files from current directory
git clean --force
Remove untracked files and untracked directories from current directory
git clean -d --force
Remove untracked files from given path
git clean --force <path>


No comments:

Post a Comment