In Lab 2: Basic Commands of Git, participants typically delve into the essential commands that form the core of Git's version control functionality. This lab focuses on hands-on experience with commands such as 'git add' to stage changes, 'git commit' to save changes to the repository, and 'git status' to view the status of the working directory. Participants may also explore 'git log' to review commit history and 'git branch' for managing branches. This foundational lab aims to deepen participants' understanding of basic Git operations, empowering them to navigate version control efficiently. Mastery of these fundamental commands is crucial for effective collaboration and version management in software development projects using Git. Successful completion of Lab 2 equips participants with the skills needed to initiate, track changes, and maintain a structured version history in their Git repositories.
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
To reset from staging area
git reset <filename>
git reset .
To hard reset from staging area
git reset --hard
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
To remove files
git rm <file name>
Then commit (no need to add)
Gets deleted from that particular branch
To delete all untracked files
git clean -n (dry run)
git clean -f
git tag –a <tag name> -m <tag message> <commit-id>
git tag
git show <tag name>
git tag –d <tag name>