Showing posts with label GIT. Show all posts
Showing posts with label GIT. Show all posts

Friday, May 16, 2014

Removing untracked files from local git branch

We can use git clean command to remove all untracked files from your local working branch.
> git clean -f

This will remove all untracked files forcefully.

To remove even the untracked directories which are present in the local branch.
>git clean -f -d



Wednesday, April 16, 2014

Writing git log output to a file

Example:
$ git log --since="04/07/2014 20:37:53" --no-merges  > C:\test.log

It will write generated git log from the specified date and time without including merges to a test.log file.

Wednesday, January 22, 2014

Git: Changing a remote URL


https://help.github.com/articles/changing-a-remote-s-url

Example:

$ git remote -v
origin  ssh://core@1.2.3.197/data/kgit/explorer (fetch)

Currently origin is pointing to  ssh://core@1.2.3.197/data/kgit/explorer


Want to change my remote url to ssh://kondal.kolipaka@gerrit.mycompany.net:29418/explorer.git

$ git remote set-url origin ssh://kondal.kolipaka@gerrit.mycompany.net:29418/explorer.git


Check after change:

$ git remote -v

origin  ssh://kondal.kolipaka@gerrit.mycompany.net:29418/explorer.git (push)

Friday, November 22, 2013

E325: ATTENTION Found a swap file by the name ".git/.MERGE_MSG.swp"

I was facing this issue while pulling the code from the git central server.

Basically error says, 2 things.

(1) Another program may be editing the same file.
    If this is the case, be careful not to end up with two
    different instances of the same file when making changes.
    Quit, or continue with caution.

(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r .git/MERGE_MSG"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file ".git/.MERGE_MSG.swp"
    to avoid this message.



I have verified (1), could not find any other terminal which was accessing this file.

I am not sure about (2), so I went ahead and deleted directly '.git/.MERGE_MSG.swp' file.

Yes, Now it worked without any issues!!!



Thursday, October 17, 2013

GIT: Finding a commit based on SHA1 ID

> git show <sha1-id>

Example: > git show e43db49

This will display the complete changes including the with commit message.

Thursday, August 1, 2013

GIT: Unlink of file 'com.x.xx/a1.jar' failed. Should I try again? (y/n) y during the pull

Unlink of file 'com.x.xx/MINIFY.jar' failed. Should I try again? (y/n) y

I was getting this issue, while pulling the code from the server using below command.
>git pull origin Dev


What I observed was, I kept it opened "build.properties' file, where all my dependent build jars are specified of a plug-in and that was causing the issue.

This could mean that another program is using the file, which is preventing git to sync the repository changes with the local changes. Sometimes the file may not be actually open in eclipse but may have been opened by a process run by eclipse. In this event, try closing the file in any applications that might have used it. If that doesn't work, completely exit any applications which may have opened the file.

Thursday, July 18, 2013

Maintaining clear git history tree

This is what I have learned from my colleague few days back.

My general workflow with git:
Git pull origin Dev-5.0
Then I would have worked for a day or two
Now, I want to push my changes for last 2 days. But, in mean time many people in my team also would have pushed the code.
Git commit  “last 2 days commits message”
Git pull origin Dev-5.0 -> get the latest code from server again
Git push origin Dev-5.0 -> push your committed changes to the server


But, this is creating a very bad hierarchy tree in git(gitk). Like below













The problem here is, while I am committing my code I don't have the latest code from central repository. This would create a different tree hierarchy in git from my last state, and only when I push my code it will merge your local branch with the central repository. Then it will connect your local branch tree node to the central tree node.

Below is the approach which has worked out for us.

Git pull origin Dev-5.0
Then you might be working for few days
Now you want to commit your changes.
Git stash   -> stash your current changes in local repository
Git pull origin Dev-5.0   -> Get the latest changes from the central repository
Now your local repository has latest changes
Apply your stashed changes on latest changes which we have pulled from central repository.
Git stash pop -> This will apply stashed changes to current changes.
If any merge conflicts, resolve them
Git commit  “my changes”
Git push origin Dev-5.0    => This would fail, if somebody else has pushed the code in mean time after your last pull, so we need to pull the code again and proceed with the push.

This is how it looks, if we maintain the above procedure.









Monday, July 1, 2013

GIT Remote Branches

You might want to figure out, what are the branches exist in the git remote repository,then you want to choose the specific one which you are looking and check them out and merge them into a local repository.

The easiest way do it:
>git branch <-a/-r>

-a => List down all branches- remote and local
-r => List down only remote branches.

Example:

K1205@K1205 /d/Work/KIDE/jsdebugger (master)
$ git branch
  Dev-5.0
  jsdebugger_plugins-master.06
* master

K1205@K1205 /d/Work/KIDE/jsdebugger (master)
$ git branch -a
  Dev-5.0
  jsdebugger_plugins-master.06
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/JSD-BETA-5.0.05
  remotes/origin/JSD-BETA-5.0.06
  remotes/origin/JSD-GA-5.0.01
  remotes/origin/JSD-GA-5.0.02
  remotes/origin/JSD-GA-5.0.3
  remotes/origin/JSD-GM-5.0
  remotes/origin/JSD-QA-5.0.01
  remotes/origin/JSD-QA-5.0.02
  remotes/origin/JSD-QA-5.0.03
  remotes/origin/JSD-QA-5.0.04
  remotes/origin/JSD-QA-5.0.05
  remotes/origin/JSD-QA-5.0.06
  remotes/origin/JSD-QA-5.0.06.01
  remotes/origin/jsdebugger_plugin-master.01
  remotes/origin/jsdebugger_plugins-master.01
  remotes/origin/jsdebugger_plugins-master.02
  remotes/origin/jsdebugger_plugins-master.03
  remotes/origin/jsdebugger_plugins-master.04
  remotes/origin/jsdebugger_plugins-master.05
  remotes/origin/jsdebugger_plugins-master.06
  remotes/origin/master

K1205@K1205 /d/Work/KIDE/jsdebugger (master)
$ git branch -r
  origin/HEAD -> origin/master
  origin/JSD-BETA-5.0.05
  origin/JSD-BETA-5.0.06
  origin/JSD-GA-5.0.01
  origin/JSD-GA-5.0.02
  origin/JSD-GA-5.0.3
  origin/JSD-GM-5.0
  origin/JSD-QA-5.0.01
  origin/JSD-QA-5.0.02
  origin/JSD-QA-5.0.03
  origin/JSD-QA-5.0.04
  origin/JSD-QA-5.0.05
  origin/JSD-QA-5.0.06
  origin/JSD-QA-5.0.06.01
  origin/jsdebugger_plugin-master.01
  origin/jsdebugger_plugins-master.01
  origin/jsdebugger_plugins-master.02
  origin/jsdebugger_plugins-master.03
  origin/jsdebugger_plugins-master.04
  origin/jsdebugger_plugins-master.05
  origin/jsdebugger_plugins-master.06
  origin/master

Friday, November 23, 2012

Template for git commit messages


Good commit messages always makes a difference!!!

Following is the template I generally refer to.



FEATURE/BUGFIX/ENHANCEMENT: KonyOne Studio - <Module name> - <short problem/module description>

<Detailed description of feature/solution description/enhancement comments>

<Fix: #JSP1234>

Reviewed By :  <reviewer name>


Example for Feature:

FEATURE: KonyOne Studio - Sky Data Explorer - Implemented model classes for sky explorer

Provided the offline support capabilities to work offline.

Reviewed by: Rakesh 


Example for BugFix:

BUGFIX: KonyOne Studio - Java Script Module - Heap memory issues with huge number of files.

Java script listener is modified..etc,..

Fix: #JSP12345


Example for Enhancement:

ENHANCEMENT: KonyOne Studio - Java Script Module - code clean for java script model

Unnecessary code has been removed in java script module.

Reviewed by: Rakesh 


Points to be considered:

  • Topic description (first line)
  •  72 characters max for each line.
  •  Give space for title and body
  •  Use present tense.(Generally git uses the same for merge/rebase)


Why 72 characters ??
git log doesn’t do any special special wrapping of the commit messages. 

On an 80 column terminal, if we subtract 4 columns for the indent on the left and 4 more for symmetry on the right, we’re left with 72 columns.


Good commit messages serve at least three important purposes:

  • To speed up the reviewing process.
  • To help us write a good release note.
  • To help the future maintainers (it could be you!), say five years into the future, to find out why a particular change was made to the code or why a specific feature was added.

Saturday, September 10, 2011

Recover lost commits in GIT

Recover lost commits in GIT:
It's a big day for me!!…I am working with GIT from last 5 days and due to some or other reason I could not push my changes to a central repository.
Generally the process I follow is commit, fetch, rebase and push paradigm everyday to make sure that my workspace is clean and latest. But, today I couldn’t go through complete process due to “fatal: malloc, out of memory “issue while doing the rebase. In the process I lost few commits but I am not sure what had happened.
I tried different options and finally I could manage to recover my lost commits with the following approach.
Please find the screenshot for memory issue.


GIT provides a greater flexibility and it manages commits as a snapshot.  Even though git status command is not saying anything about your commits but it will be there somewhere in your local repository.
Here you go...
Step 1: Check git reflog to see all your commits.
Ø  Git  reflog show

This will show all commits which you have done in your local repository including your lost commits.
Every commit will have a hash id, identify the hash id for your lost commit.
Ex:  Here, my lost commit id is “85123ef”.
Step 2:  Confirm your commit
Ø  Git  show  85123ef
This will clearly show you the description and change id of your commit.

Step 3:  Do checkout for your hash id.
Ø  Git  checkout   85123ef
This will recover your lost commit and take you back to where we were at the beginning.