Sunday, April 11, 2021

git reflog and its importance

Command `git reflog` is very helpful when you want to revert changes. It is little different than `git log` command as `git log` lists all the commit ids but using `git reflog` you can see only those commit ids which are pulled on the server.

Suppose a developer works on a task and commits frequently. He/She has committed 11 commits i.e. commit 1, commit 2, .... commit 11 before pushing these changes on the server. DevOps pulls these changes on the server. Now developer commits 9 more changes before pushing them on the server so he/she has pushed two times on the server but he/she has committed code 20 times. If this second push has broken something on the server and It is asked DevOps to revert the push.

DevOps checks the commits using command `git log` but he/she sees 20 commits, DevOps is not sure about the commit number before second pull, he can discuss with developer but developer might not sure too as his/her concentration was on the code & error and not on the commit number. It was DevOps responsibility about every details of the pull / push and here `git reflog` comes to the rescue.

It lists only those commits which were pulled on the server. The number of times developer pushed the code, it lists only those commit number. It is independent of the number of commits done by developer. Yes, if developer pushes code after every commit then it will list all the commit numbers but developers do not push code in the repository after every commit.

 


 


Thursday, March 18, 2021

git - check branch of detached head

If your git branch is in detached head state and you want to know the branch name of this detached head state, this is a simple solution for you.

cd into your git project directory and run the command. 

git branch --contains HEAD

This way you can find the correct branch of your git project dir.


In above screenshot, head is detached from branch branch-two.

If user wants to know the branch name from where head was detached, above command is the solution.

You can see in the above screenshot that we can find the detached head branch using above command.


Thursday, February 11, 2021

pip install error - sys.stderr.write(f"ERROR: {exc}")

If you are getting the following error while installing a pip package, this solution should work for you.

sys.stderr.write(f"ERROR: {exc}")

Solution :

A) If you are installing a pip package with default python (2.7) and getting above error, run following command


curl https://bootstrap.pypa.io/2.7/get-pip.py --output get-pip.py
python get-pip.py

B) If you are installing a pip package with python3 and you are installing a package using pip3 command, run following command


curl https://bootstrap.pypa.io/3.5/get-pip.py --output get-pip.py
python3 get-pip.py

Change the python version in url, it depends on your system's python version.

C)  If you are installing a pip package in a virtual environment with python3.5,  run following command in your virtual environment


curl https://bootstrap.pypa.io/3.5/get-pip.py --output get-pip.py
python3 get-pip.py
Command python or python3 both should work same in the virtual env.