diff --git a/new_Git_commnads b/new_Git_commnads new file mode 100644 index 0000000..c0bf27e --- /dev/null +++ b/new_Git_commnads @@ -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 - removes commits and goes back to the commit for that hash code + + +git reset --source 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 - 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 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 - 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 - 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 - used to revert the changes done in the bad commit that introduced the bug in the code.