Author Archives: Vineet Gupta

Git – Remove in between commit

Our team is doing several projects in PHP. We have wrongly committed a folder of One Project to another. Now, we want to remove that particular commit from the Project. If we remove the particular folder/commit from project then there is no issue for our project.

If we just remove the folder and issue the new commit at current position then folder is removed but it will remain in the history of Git. So, we want to remove it completely from refs, history and other things from Git.

We can also create a separate branch but the commit refs of authors would be lost. We want to only remove that particular commit. We have no issue in rewriting history or re-basing it but don’t know how to do it.

In the project we have done 136 commits and want to remove commit no.76th. The required information about SHA is as under:

5d39775b //136th commit
a4df5ee9 //135th commit
6971cf35 //134th commit
162f833c //76th commit
32603274 //75th commit
9770059 //1st commit

Methods for resolving issue

I have tried all the provided methods i.e. rebase and cherry-pick. I here to provide full information about both the methods tried and things done by me, to help to understand things with better view


To check which is best I have done these things:

  1. Fork the remote repo so that the original would be intact and things can be understood easily. So, don’t do any original repo until you are sure things done are correct or not.
  2. first taken the clean copy of Git Repo. Generally, whenever we stash or do other things that are also stored in Git as local Git database. So, that Git database doesn’t have any local or temporary things.
  3. I have calculated total number of bytes taken by folder .git. As the repo is clean the minimum bytes would be correct here. To go further deep, I have noted down both bytes taken and bites taken on disk. As both are different things and they are:bytes – 7,963,769 and size on disk – 8,028,160
  4. If you are using Windows and have installed any Anti virus then you have to disable the Active/Real time mode. As doing things Git need fast access of i/o files checking. What happens when file is created by Git, the active mode locks the new Created for checking virus and when Git tries to re-access that it fails due to locking by Antivirus. In Case of failure you have start your process again from 1.

Method I – Rebase

In re-basing method can be done by two ways. One is through –onto and other is with -i.

-i Method

I used the following command:

git rebase -i 162f833c^

and it had opened the vim Editor and I see the list of commits starting from 162f833c not from master. If the end the following lines are provided.

# Rebase 3260327..5d39775 onto 3260327
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like “squash”, but discard this commit’s log message
# x, exec = run command (the rest of the line) using shell
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.

I removed a line so that commit will be lost and saved the file and quit the Editor and when I quit it started re-basing as showing:

Rebasing ( 1/64) ..(2/64)Successfully rebased and updated refs/heads/master.

And then tried to check the log to see that commit is lost or not and in the log I couldn’t find the commit I want to delete. Means the successfully completed the command. The I tried to check the status as:

# On branch master
# Your branch and ‘origin/master’ have diverged,
# and have 64 and 65 different commit(s) each, respectively.

Since the commits is deleted but on the remote from which it is derived required to be pushed. So, pushed the commit with the force to override earlier code.

git push -f

After that I removed the local repo and re-fetched again the repo and the size it shows:

bytes 6,831,765 bytes
size on disk 6,897,664 bytes

–onto Method

After going through Many blogs and Manual, I found 1 blog here which really let me know how to use it. So the command I used is:

git rebase –onto 3260327 79504a5~1

and the out put is:

First, rewinding head to replay your work on top of it…
Applying: 77th Message
Applying: 78th Message
Applying: 79th Message
Last commit

And then tried to check the log to see that commit is lost or not and in the log I couldn’t find the commit I want to delete. Means the successfully completed the command. The I tried to check the status as:

# On branch master
# Your branch and ‘origin/master’ have diverged,
# and have 64 and 65 different commit(s) each, respectively.

So, with single command all the things are done and then I done a force push to check the bytes etc as earlier

git push -f

After that I removed the local repo and re-fetched again the repo and the size it shows:

bytes - 6,831,389
size on disk - 6,893,568

Rebase -i Vs –onto

Thus, after doing rebase method. I really approve the –onto method for deleting the commit in between as it is single command and the bytes are also saved marginally higher then -i method. The real advantage is that we don’t have to do additional things in –onto method.

Method II – Cherry-pick

Cherry-pick really nice method but run through many commands and you have to take little cautions running the commands. First, I have to create a separate log file with

git log –all –decorate –oneline –graph > 1

Which showed me the log of the repo as we need to view it again and again. From this repo identify the commit you want to delete and copy the SHA Key the last good commit meaning thereby identify the commit up to which we didn’t want to change any thing. So, the next command would be

git checkout 3260327 -b repair

generated output:

Switched to a new branch ‘repair’

So, up to last Good commit we have created a new branch. So, things up to last Good commit doesn’t change. Again I run the following command to view all the good commits:

git log –decorate –oneline –graph > 2

I have removed the world –all as, I want to view the commits of branch repair only. As it showed me Good Commits upto marked correctly. Now, next command is to be used with caution as it is includes the bad commit as starting point and end point the last commit done and it would be as:

git cherry-pick 162f833..5d39775


[repair 9ed3f18] xxxxxx
x files changed, xxx insertions(+), xx deletions(-)
[repair 7f06d73] xxxxx
xx files changed, xxx insertions(+), xx deletions(-)

What this command does that it recommits all the commits leaving first commit provided above i.e (162f833) to last commit (5d39775) provided. So, the sha commits value would be changed accordingly as it is recommitting the commits one by one. Now it is the time to view the log as:

git log –all –decorate –oneline –graph > 3

output as:

* f61a9a5 (HEAD, repair) xxxxxx
* 25be3b9 xxxxx
* 49be029 xxxxx
| * 5d39775 (origin/master, origin/HEAD, master)
| * a4df5ee xxxxx
| * 6971cf3 xxxxxx
| …….
| …….
| * 162f833 xxxx
* 3260327 xxxxx
* 9770059 xxxxx

So, viewing graph let us know that it had re-commits all the commits except the bad commit. showing you all the old sha keys with new keys. If everything is all right we have to make repair branch as master and deleting the master branch as:

git checkout master

and output as:

Switched to branch ‘master’

First checkout master branch so that we can over ride the changes on master branch. Then

git reset –hard 3260327

and output as:

HEAD is now at 3260327 xxxxx

It will discard the commits after the good commit and now we have to merge the repair branch with master:

git merge repair

and output as:

Updating 3260327..40d290d

Now, if you view the log it will not show you the bad commit and every thing is done. I done a force push to check the bytes etc as earlier

git push -f

After that I removed the local repo and re-fetched again the repo and the size it shows:

bytes - 6,831,556
size on disk - 6,897,664

Ranking of commands

Rebase –onto [First]

bytes – 6,831,389
size on disk – 6,893,568

Cherry Pick [second]

bytes – 6,831,556
size on disk – 6,897,664

Rebase -i [third]

bytes 6,831,765 bytes
size on disk 6,897,664 bytes

I would like to give preference to git rebase –onto command as things are done clean way with single command easily.

SEO – Keywords and Ranking Factor

Everybody want to gain maximum amount of Traffic of Web and this can only reached through Optimization of Web site. For those who know what effects the Page Ranking its an easy task and for others is a hell of a Job. The one and the most important thing about Optimization is the Keywords. So, which keywords one use on different pages is always a great concern and another is the effect of specific keyword on the page ranking. Following are the places where to use the Keyword and at which position are:

1. Keywords in Title Tag

Keywords in the title is one of the most important in Search Engine Optimization. I would say that Keywords in Title Tags works as spotlight for attraction of the Web Traffic. Keywords in Title are compared with contents and other things. Sometime ago, I have written the Article about , which describes the importance of Title Tag. Now, I will let you know the effects and how they are relevant to the Optimization are:
i) Keywords use anywhere in the Title Tag. First Optimization rule is always use the Title Tag Keywords on Web Page. If the words in Title Tag are used as Heading Tag then the importance of the Web Page increases. Try to provide the Meaning full Title Tag. Always try to create title for Human Beings and not for Computers it creates more relevancy.
ii) First Word of Title Tag:  All the Keywords provided in Title Tag are important, but the First word gives the more importance and to make more relevancy don’t use the First Keyword as Website Name and Make sure that it is in proper case. As the uppercase and lowercase gives the impression that it is for robots and generated/created by computer itself as the Proper Case is only written by Human beings but can also achieved through small Programming.
iii) Keywords stuffing: Don’t try to over stuffing the Title Tags as the going beyond the limits is always dangerous. Most of the work of Ranking is done by robots/programming and stuffing of irrelevant keywords makes it give negative points. Thus, it is always advised to use the Keywords which are relevant to your webpage and not to the relevant about the article. Try to find out appropriate title through searching the web also.
iv) Length of Title Tag: It is mostly seen on many blogs the recommendation of Length of the Title, some say it would good to have 65 characters Length and some says it as 120 and even I come across some websites which has written about 300 character length of the Title tag. According to me, Length of the Title Tag Should be more than 80 Characters. Why 80 Characters, the most of the computer programs are written through command line operation and you would be surprised that starting programs like wordstar, Lotus 123 and many other Dos based programs have 80 Columns length. Even today all the Emails are set with the maximum length of 80 Characters, if you view the source code.

2. Keywords in Anchor Tag

Anchor Text keywords plays very important effect on the optimization rules. Sometime before, I had written a small article on , which describes how the keywords plays an important role in assessment in web page. It is also important to note that Internal and External Anchor text are assessed differently and the number’s of Internal and External Links also effects the Optimization. Don’t try to give hundred’s of Internal/External, giving excessive Links would also punish’s the Web Pages.

3. First 50-100 Words on Web Page

It is very important to note down that First 50 words of the web page are very important and the relevancy of First 50 Words are compared with Keywords in Title Tag and also with Anchor Tags, It becomes more important which these 50 words when the reader is robot. Robot is not a human being and the First 50 words are considered more important in determination of Category and Other things about web Page. For reading the First word of the Web page HTML are deleted and read every words from HTML Body Tag, as the Processing of Header Tag is done differently.

4. Keywords in Image Alt

Images plays important part for users as it is very well said A Picture can describe things instantly to every one even without speaking a word. Don’t try to use the heavy pictures which will slow down the loading of the website. Keywords used in ALT has of Image and the Keywords in Anchor Text/Title/Heading Tags are viewed as co-relation with each other. Robots are not human beings and the Pics are irrelevant to them but by the keywords in ALT tag to describe the Picture plays an important role.

5. Keywords in Page Url

I believe that keywords used in page URL are now considered as very important and nowadays even more important than Title tag. The major effect I have seen these days the search query of the Google, if you view the changes made in the Google query term of searching you will find that earlier they are using variable `q` as to describe the keywords for searching purposes and nowadays if you view the search string of Google you will find that they had replaced the `q` with `url` with indicates that the Keywords in Page Url are considered more relevant than page title or even the contents of the web page.

6. Keywords in Meta Description

Providing the good description to the Web Page is important as in most cases I have found that the Search Engine prefer to display the title and meta tag description as results. Try to include the Title/Anchor/Heading/Url keywords in Meta Tag Description. But there is no proof upto now that Keywords in Meta Description plays any role in Indexing purposes. I have found that Meta Tags are used to access the relevancy of the Web Page rather than providing a ranking factor, thus it become more important to provide the Keywords in Meta Tag Description.

7. Keywords in i or em or strong Tags

Words used to highlight the text as bold or underline and other such things and Keywords are considered as Raking Factors, Thus the keywords used in bold etc are also become the important part of the SEO rules.
Tagged , , , , , , , ,
%d bloggers like this: