LAB 2: Basic Commands of Git

1 .gitingnore

Step 1: Create .gitignore file and give pattern matching (e.g. *.class, *.jar)

vi .gitignore
(Press i)
\*.class
\*.jar
(Press esc)
:wq!

Step 2: Add & Commit .gitignore file

git add .gitignore
git commit -m ".gitignore"

Step 3: Add some files for testing

touch 1.txt 2.txt 3.txt
touch 4.class 5.class 6.class
touch 7.jar 8.jar 9.jar
ls
git add .
git status
  1. Resetting changes (Before Commit)

To reset from staging area

git reset <filename>
git reset .

To hard reset from staging area

git reset --hard
  1. Reverting changes (After Commit)

To revert the changes

git revert <commit-id> 

Revert will create a new commit-id (all changes will be tracked) 
You need not to add and commit again. Automatically new commit-id will be generated
  1. Removing files

To remove files

git rm <file name>


      Then commit (no need to add)
      Gets deleted from that particular branch
  1. Deleting all untracked files

To delete all untracked files

git clean -n (dry run)
git clean -f
  1. TAGs

To apply tag

git tag –a <tag name> -m <tag message> <commit-id> 

To see the list of tags

git tag

To see particular commit content by using tag

git show <tag name>

To delete a tag

git tag –d <tag name>