Debug School

rakesh kumar
rakesh kumar

Posted on

checklist of git command with examples

git init: Initializes a new Git repository in the current directory. Example: git init

git add : Adds a file to the staging area, ready to be committed. Example: git add file.txt

git commit -m "commit message": Commits changes to the repository with a message describing the changes. Example: git commit -m "Added new feature"

git status: Shows the status of the working directory and the Git repository. Example: git status

git log: Shows a list of all commits made to the repository. Example: git log

git branch: Lists all branches in the repository. Example: git branch

git checkout : Switches to a different branch. Example: git checkout dev

git merge : Merges a branch into the current branch. Example: git merge feature-branch

git push: Pushes changes to a remote repository. Example: git push origin master

git pull: Pulls changes from a remote repository. Example: git pull origin master

git clone: Creates a copy of a remote repository in a new directory. Example: git clone https://github.com/username/repo.git

git remote add : Associates a remote repository with the local repository. Example: git remote add origin https://github.com/username/repo.git

git fetch: Retrieves changes from a remote repository without merging them. Example: git fetch origin

git reset: Resets the current branch to a specific commit. Example: git reset HEAD~1

git rebase: Applies changes from one branch to another. Example: git rebase master feature-branch

git tag: Creates a new tag to mark a specific point in the repository history. Example: git tag v1.0.0

check only last 20 Commits id in git

To see only the last 20 commit IDs in Git, you can use the git log command with the --pretty=oneline and --max-count=20 options. Here's the command:

git log --pretty=oneline --max-count=20
Enter fullscreen mode Exit fullscreen mode

This will show you the last 20 commit IDs, along with their commit messages, in a single line format. The output will look something like this:

1b367f7420c8a38a7d3e3e35d3b1c9b3e305d2f2 Added new feature
86b8c235a7a582a37dbb18716d7432ac9f1e9e1d Fixed bug in login form
ec56e52732d75e1d4726ebf02cbafff8eaf7a0d4 Updated user profile page

check only last 20 Commits id in git

git log --pretty=oneline --max-count=20
Enter fullscreen mode Exit fullscreen mode
1b367f7420c8a38a7d3e3e35d3b1c9b3e305d2f2 Added new feature
86b8c235a7a582a37dbb18716d7432ac9f1e9e1d Fixed bug in login form
ec56e52732d75e1d4726ebf02cbafff8eaf7a0d4 Updated user profile page
Enter fullscreen mode Exit fullscreen mode

How to check today Commits id in git

git log --since="midnight"
Enter fullscreen mode Exit fullscreen mode
git log --since="midnight" --pretty=format:"%h"
Enter fullscreen mode Exit fullscreen mode

how to cancel today all git pull using commits id
reverting-to-a-specific-commit-based-on-commit-id-with-git
step 1:

git log --since="midnight" --pretty=format:"%h"
Enter fullscreen mode Exit fullscreen mode

step 2:

git reset --hard c14809fa
Enter fullscreen mode Exit fullscreen mode

Top comments (0)