releases
or version
numbers.
Lightweight tags:
git tag v1.0.0 // tags for previous commits (refers to the last commit)
git tag v1.0.0 <commit-hash> // tag for specific commit
Annotated tags:
git tag -a v1.0.0 -m "Version 1.0.0 release"
checkout to tag:
git checkout v1.0.0
git checkout master // to return the last commits again
Listing all tags:
git tag
Deleting a tag: // deletes only tag - not commits
git tag -d v1.0.0
Create a tag for a branch:
git tag v1.0.0 master
push tag to a remote repository
git push origin v1.0.0
git reflog
Using the git reflog command should reveal Git's internal diary of all of the commits that HEAD has pointed to in your local repository—even the ones you thought were lost forever (assuming they weren’t old enough to have expired).git whatchanged --since='2weeks ago'
Shows commit logs and diff output each commit introduces.git init
Step 2: create index.html file and 2 commit m1,m2
add text "m1" into index.html and commit as m1
echo "m1" > index.html
git add .
git commit -m "m1"
add text "m2" into index.html and commit as m2
echo "m2" >> index.html
git add .
git commit -m "m2"
Step 3: create feature branch and checkout
git checkout -b feature
Step 4: create feature folder&file
create feature.html into the feature folder and add text "f1" then commit as f1
echo "f1" >> feature/feature.html
git add .
git commit -m "f1"
Step 5: Checkout to master
git checkout master
Step 6: add text "m3" into index.html and commit as m3
echo "m3" >> index.html
git add .
git commit -m "m3"
Step 7: Checkout to feature
git checkout feature
Step 8: add text "f2" into feature.html and commit as f2
echo "f1" >> feature/feature.html
git add .
git commit -m "f2"
Step 9: Checkout to master
git checkout master
Step 10: Merge feature branch into master with squash
git merge --squash feature
Step 11: See git status because files we will have into the staging area and we need create a commit for it
git status
git commit -m "Merge feature branch into master"
git init
Step 2: create index.html file and 2 commit m1,m2
add text "m1" into index.html and commit as m1
echo "m1" > index.html
git add .
git commit -m "m1"
add text "m2" into index.html and commit as m2
echo "m2" >> index.html
git add .
git commit -m "m2"
Step 3: create feature branch and checkout
git checkout -b feature
Step 4: create feature folder&file
add text "f1" into feature.html and commit as f1
echo "f1" >> feature.html
git add .
git commit -m "f1"
Step 5: Checkout to master
git checkout master
Step 6: add text "m3" into index.html and commit as m3
echo "m3" >> index.html
git add .
git commit -m "m3"
Step 7: Checkout to feature
git checkout feature
Step 8: rebase master branch into feature
git rebase master
Step 8: add text "f2" into feature.html and commit as f2
echo "f2" >> feature.html
git add .
git commit -m "f2"
Step 9: Checkout to master
git checkout master
Step 10: Merge the feature branch into master
git rebase feature
git init
Step 2: create index.html file and 2 commit m1,m2
add text "m1" into index.html and commit as m1
echo "m1" > index.html
git add .
git commit -m "m1"
add text "m2" into index.html and commit as m2
echo "m2" >> index.html
git add .
git commit -m "m2"
Step 3: create feature branch and checkout
git checkout -b feature
Step 4: create feature folder&file
create feature.html into the feature folder and add text "f1" then commit as f1
echo "f1" >> feature/feature.html
git add .
git commit -m "f1"
Step 5: Checkout to master
git checkout master
Step 6: add text "m3" into index.html and commit as m3
echo "m3" >> index.html
git add .
git commit -m "m3"
Step 7: Checkout to feature
git checkout feature
Step 8: add text "f2" into feature.html and commit as f2
echo "f1" >> feature/feature.html
git add .
git commit -m "f2"
Step 9: Checkout to master
git checkout master
Step 10: Merge the feature branch into master
git merge feature
as the result, we will get a new commit Merge branch 'feature'
author and last commit information
for each line in a file, helping track the origin of changes.
Create a file and add some content:
echo "Line 1" > myfile.txt
echo "Line 2" >> myfile.txt
echo "Line 3" >> myfile.txt
Add and commit the file:
git add myfile.txt
git commit -m "Initial commit"
Make changes to the file and commit them
Make changes to the file and commit them
git blame myfile.txt
02fa3e76 (Luka 2023-06-01 20:07:40 +0400 1) Line 1
02fa3e76 (Luka 2023-06-01 20:07:40 +0400 2) Line 2
02fa3e76 (Luka 2023-06-01 20:07:40 +0400 3) Line 3
91354ada (Luka 2023-06-01 20:08:10 +0400 4) Line 4
91354ada (Luka 2023-06-01 20:08:10 +0400 5) Line 4
7ba66ba6 (Luka 2023-06-01 20:08:23 +0400 6) Line 5
echo "This is the initial content." > myfile.txt
add and commit file
git add myfile.txt
git commit -m "Initial commit"
make changes
echo "This is the modified content." > myfile.txt
git add myfile.txt
git commit -m "Modified myfile.txt"
revert last commit
git revert HEAD
or we can use specifying with the commit ID
git revert 4c04ecc
git log will return
Revert "added file 4" --- Commit name
This reverts commit 4c04eccff32e195ac0df17b1543f7f81de32d938. --- Commit id
echo "This is an example file" > file1.txt
echo "Another example file" > file2.txt
Add the files
git add file1.txt file2.txt
git commit -m "Initial commit"
Search for the word "example"
git grep "example"
Use a regular expression to search for words starting with "ex":
git grep "ex\w*"
Perform a case-insensitive search for the word "example":
git grep -i "example"