Skip to content

Create new_Git_commnads #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions new_Git_commnads
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
git restore . - restores the files to the previous commit/ undos all the local changes that haven't been committed.


git restore index.html - restores only that particular file to the recent commit/ undos all the local/uncommitted changes for that file.


git reset --hard <hash code of the commit> - removes commits and goes back to the commit for that hash code


git reset --source <hash code> index.html>- removes commits and goes back to the commit for that hash code only for that particular file.


git commit --amend -m 'Your message'- helps re-write messages


git revert <hash code>- helps to roll back to a previous commit by creating a new commit for it. Doesn't removes those commits from the log like git reset does.


git reflog- this can be useful to bring back deleted commits/files/changes. Use git reset <hash code of lost commit from reflog> to bring back rolled changes.


git reset HEAD~2- Helps roll back by 2 commits and unstage all the changes in those 2 removed commits.


git reset HEAD~2 --hard


git rebase (most useful command)- Reapply commits on top of another base tip. ex. git rebase master sets the branch at the tip of master branch


git bisect start- starts the searching procedure to find the bad commit.

(Optional) Use the command git bisect good <hash-code of the commit that you are sure doesn't have the bug>- usually this is the first or the second commit and tells git to start from the middle.

git will start checking out commits on its own, you have to test the commit and let git know if the commit has the bug or not by using commands,

git bisect good- if the commit is fine
git bisect bad- if the commit has the bug.
After giving feedbacks, git has a feedback tree that it uses to return the commit that introduced the bug/ the first bad commit, you can copy its hash code. The reference refs/bisect/bad will be left pointing at that commit.

After a bisect session, to clean up the bisection state and return to the original HEAD, issue the following command:

git bisect reset- By default, this will return your tree to the commit that was checked out before git bisect start.

git bisect reset <commit>- For example, git bisect reset bisect/bad will check out the first bad revision, while git bisect reset HEAD will leave you on the current bisection commit and avoid switching commits at all.

git revert <hash-code of the bad commit>- used to revert the changes done in the bad commit that introduced the bug in the code.