Hasan's Post

Tutorial repository

View on GitHub
8 July 2021

Fixing mistakes and bad comments

by Hasan

source Corey Schafer Tutorial

Basic command line tutorial can be found here

Branch change

git checkout another_branch. Here another_branch was the branch which was previously identical to master branch.

Wrong Commit Message

Wrong branch Commit

* ``git log`` we will pick the hash of last commit(full hash not necesarry 6/7 is enough). Copy this hash part.
* ``git checkout another_branch`` here another_branch is the branch where we wanted to the commit. Now if we perform ``git log`` we will see that we have only one commit. Then we will do ``git cherry-pick copied_hash``.Now if we want to see the ``git log``. So we have our commit in our another_branch. Now we want to change the master branch. ``git checkout master``. Now we are in master branch. We have 3 types of reset.
           1. git reset --soft
           2. git reset --mix(default)
           3. git reset --hard
So again we will copy the commit hash. We will do `` git reset --soft copied_hash``. Now ``git log`` shows that we no longer have the commit. However ``git status`` will show that we have some files in our staging area.
If we perform mix reset. ``git reset copied_hash``. Agian ``git log`` will show that we have only one commit.``git status`` will show that we have files not in staging area but in working directory. Now in that case we actually donot want our files here we just want them to remove. ``git reset --hard copied_hash`` . __Be careful in real world application before reseting this__. 
Now we if again see that ``git status`` there will be `.ignore` file still untracked. ``git reset --hard`` reverts all of the tracked files back to states they were, and left untracked files alone. Getting rid of untracked files ``git clean -df`` here d=directory, f=file. Now ``git status`` will show that we have our desired situation.

Getting file after hard –reset (reflog)

Correcting Commit after Pushing to remote (git revert)

tags: