# Checkout & Reset

## Checkout Commit

```
// Get commit hash
D:\work\emclas>git log --oneline -n 3
471f9f7 extra chunk call issue fix
9827818 blank worker call prevented
99e0156 chunkno -1 added

// checkout commit
git checkout 9827818

// make changes, but do not checkout to other branch elase changes would be lost
// to retain changes create new branch out of it
git checkout -b newbranch // now you can checkout to other and merge this to other branch
```

## Overrite file from remote

```
git checkout <hash> myfile.txt
git commit -m "msg" // git add not required in this case

// undo above change
git checkout HEAD myfile.txt
```

## Revert last commit

```
// revert to last commit, create new commit , maintain history 
git revert HEAD

git reset myfile.txt ( unstage file, file revert to modified state )
git reset ( unstage multiple file )

git reset --hard // reset all changes, including staged changes
```

## Hard reset ( dangerious )

Still untracked files remains in repo. to clean it use `git clean -df`

```
471f9f7 extra chunk call issue fix
9827818 blank worker call prevented
99e0156 chunkno -1 added

git reset --hard 99e0156 // all commits after it is completely gone
```

## Clean

Often used with --hard reset

```
git clean -f ( remove untracked files)
git clean -df ( remove all untracked file and directory )
git clean -xf ( remove all untracked file and directory even that is listed in .gitignore file )
```

## Undo ( reset files from repo)

```
git checkout -- . ( all )
git checkout -- index.html ( specific file )
```
