git amend scenerios

Sometimes we need to change the commit message of already committed/committed-pushed files. See below some of the scenarios might arise..

Scenerio 1-> Committed but not pushed

$ git commit –amend

This will open an editor with the commit message. If you are using vi editor edit the commit message and save using !wq: Check with $git log if the message has been amended correctly.

Scenerio 2-> Already pushed + most recent commit

It might be the case that if a user has already pushed the changes to git central repository, in this type of scenario we need to first amend the most recent local commit and afterward apply –force push which will forcefully push the changes to the server. In this process, one thing to keep in mind is that if in between any other user who has already synced local copy with the central repository needs to re-pull.

$ git commit –amend
Edit the message in vi and save and exit
$ git push origin <branch_name> –force


Scenerio 3-> Not pushed + old commit

$ git rebase –i HEAD~X

where X is the number of commits to go back then move to the line of your commit, change pick and edit then change your commit message

$ git commit –amend

Finish the rebase with:

$ git rebase –continue

Rebase opened your history and let you pick what to change. With edit, you tell that you want to change the message. Git moves you to a new branch to let you –amend the message. git rebase — continue puts you back in your previous branch with the message changes.

alternatively, you can choose reword instead of edit when rebasing to change the commit directly. Then you can skip the amend and rebase continue. You may check this link from git book for more on this.

Scenerio 4-> Already pushed + old commit
Edit your message with the same 3 steps process as menined in scenerios 2 ( rebase –i, commit –amend, rebase –continue). Then force push the commit

$git push <branch_name> master –force

But! please remember re-pushing your commit after changing it will very likely to prevent others to sync with the repo, if they already pulled a copy. You should first check with them.


References:
https://gist.github.com/nepsilon/156387acf9e1e72d48fa35c4fabef0b4

https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History


SpaceVim review

As a Vim user for nearly 2 decades, recently I got an opportunity to explore
SpaceVim a new Vim distribution. Some of the features worth highlighting are:

  • Nicely built edit mode.
  • Loved the idea of collecting related plugins together to provide features.
  • Instant search results using grep, ag, rgackpt and with a great UI.

Will exlore more features in coming days and shall update the post.

Gitbub:https://github.com/SpaceVim/SpaceVim

Out of memory Cent OS Linux: unicode_start hang issue: Solved

My Cent OS 5.6 RHEL based virtual machine has suddenly became very slow ..almost died 🙁 after few min I saw a message on console related to “Out of memory“, after doing a bit analysis and search I found that this is a known issue and also reported in redhat bug tracker (obviously got resolved in upstream versions).
Reason: Problem is that setting BASH_ENV=~/.bashrc runs /etc/profile, which sources /etc/profile.d/lang.sh. If TERM=linux, lang.sh runs /bin/unicode_start sending the whole process into an infinite loop.

I found two solutions (as of now)

1. Open vi /etc/sysconfig/i18n this file contains a reference to unicode (UTF-8). We have take out all the references to UTF-8)

Code before:

[code lang=”js”]
LANG="en_US.UTF-8"
SUPPORTED="en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
[/code]

Code after:

[code lang=”js”]
LANG="en_US"
SUPPORTED="en_US:en"
SYSFONT="latarcyrheb-sun16"
[/code]

2. Another solution is to change the shell from “bash” to “sh” in unicode_start script
We need to open the vi /bin/unicode_start and from first line change “#!/bin/bash” to “#!/bin/sh“.

References: https://bugzilla.redhat.com/show_bug.cgi?id=622981