Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

Calculate Stats of github ( git ) project

Lets say we want stats of ORC project

git clone https://github.com/apache/orc.git

Clone gitstats project also

git clone https://github.com/hoxu/gitstats.git
cd gitstats/

Calculate stats

./gitstats /Users/jagatsingh/dev/code/open/orc /Users/jagatsingh/dev/code/open/gitstats/orc_stats
open '/Users/jagatsingh/dev/code/open/gitstats/orc_stats/index.html'

You need following installed on your machine

* Git
* Python
* Gnuplot

Git clone via ssh tunnel

Follow the steps mentioned in below post to configure ssh tunnel
http://jugnu-life.blogspot.com/2015/04/ssh-tunnell.html
Then in git
git config --global http.proxy 'socks5://127.0.0.1:9999'

git config --global https.proxy 'socks5://127.0.0.1:9999'
Now you can do the git clone

Using git behind proxy

Source

If the URL is of the pattern 

git ://

Then

I found the instructions on some page.

I've pasted them here for easier access.

Basically the steps are:

1 - sudo apt-get install socket

2 - in your home directory, put a shell script called "proxy-cmd.sh"

containing (replace YOUR_PROXY and YOUR_PROXY_PORT with your own proxy

parameters):

#! /bin/bash

(echo "CONNECT $1:$2 HTTP/1.0"; echo; cat ) | socket YOUR_PROXY

YOUR_PROXY_PORT | (read a; read a; cat )

3 - chmod +x proxy-cmd.sh

4 - export GIT_PROXY_COMMAND=<PATH TO YOUR SCRIPT>/proxy-cmd.sh

Note: you can export GIT_PROXY_COMMAND in your ~/.bashrc file to make

this permanent 

If the url is of the pattern

http

then

git config --global http.proxy http://myproxy.domain.com:1234

git add all deleted for commit

Removing the git merge commit if no commit has been made to master

Removing the merge commit if no commit has been made to master

$ cd gitlearn/
$ ls
$ git init
Initialized empty Git repository in /Users/jaggija/dev_home/code/open/gitlearn/.git/

Create some text file in master

$ pwd
/Users/jaggija/dev_home/code/open/gitlearn
$ vi readme.txt
$ git add readme.txt 
$ git commit -m "Initial commit"
[master (root-commit) 5202907] Initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 readme.txt

Create a new branch and edit the text file

$ git checkout -b "new branch"
fatal: 'new branch' is not a valid branch name.
$ git checkout -b "newbranch"
Switched to a new branch 'newbranch'
$ git checkout newbranch
Already on 'newbranch'
$ vi readme.txt 
$ git add readme.txt 
$ git commit -m "new branch"
[newbranch 0ec90b8] new branch
 1 file changed, 2 insertions(+)


See the log


$ git log
commit 0ec90b8fd3174fe0ad8d0e538f5c7a162a0b2216
Author: Jagat Singh <jaggija@cba.com.au>
Date:   Mon Jul 21 10:17:32 2014 +1000

    new branch

commit 52029078b1635437aec297321c5d23274267e7d6
Author: Jagat Singh <jaggija@cba.com.au>
Date:   Mon Jul 21 10:16:23 2014 +1000

    Initial commit


Switch to master and do the merge


$ git checkout master
Switched to branch 'master'

$ git merge --no-ff newbranch
Merge made by the 'recursive' strategy.
 readme.txt | 2 ++
 1 file changed, 2 insertions(+)


$ git log
commit 4778269d6e3a8be0a68b904653f349b0252736b0
Merge: 5202907 0ec90b8
Author: Jagat Singh <jaggija@cba.com.au>
Date:   Mon Jul 21 10:19:43 2014 +1000

    Merge branch 'newbranch'

commit 0ec90b8fd3174fe0ad8d0e538f5c7a162a0b2216
Author: Jagat Singh <jaggija@cba.com.au>
Date:   Mon Jul 21 10:17:32 2014 +1000

    new branch

commit 52029078b1635437aec297321c5d23274267e7d6
Author: Jagat Singh <jaggija@cba.com.au>
Date:   Mon Jul 21 10:16:23 2014 +1000


See the graph

$ git log --oneline --graph
*   4778269 Merge branch 'newbranch'
|\  
| * 0ec90b8 new branch
|/  
* 5202907 Initial commit


Lets fix the merge commit

$ git reset --hard 5202907
HEAD is now at 5202907 Initial commit
$ git status
On branch master
nothing to commit, working directory clean

Do fast forward merge

$ git merge --ff-only newbranch
Updating 5202907..0ec90b8
Fast-forward
 readme.txt | 2 ++
 1 file changed, 2 insertions(+)

See the log again

$ git log --oneline --graph
* 0ec90b8 new branch
* 5202907 Initial commit
$ git status
On branch master
nothing to commit, working directory clean
$

Done


Git Tutorial

git init learngit

This will create a new git repo in the folder named learngit.

We are ready now to use git within our local system.

When we say git init , it creates a directory named .git inside the folder.
This contains the stuff needed by git to work.

If you want to copy existing code base in git to your local system , you have another way.

git clone url_name

Create a new file named readme.txt

Add some content to it

git add readme.txt

This command it telling that i want this file to be considered for saving it git.
When we say this , git stores that to index.

Commit the file

git commit --message "Adding a new file"

This command saves the file which we added to index into the git.

git log

Git log shows the history about what work has been done and by whom

git diff

We can use this command to find difference the two commits

git diff master~1 master

Another similar syntax is
master^1


This will show changes to all the files onto master on current version from previous commit

git diff master~1 master --filename.txt

If you want to see diff only for specific file you can use above command.

git diff

without an argument views the differences between the current
working directory and the index staging area.

git diff master

views the differences between the current working directory and the last commit on the
default master branch


While working with word documents you might want to use the

--word-diff

This shows diff at the word level rather then lines

git diff --word-diff master~1 master --filename.txt

Another format of diff is

--stat

This command shows the summary in terms of line changes + and - , rather than details about changes.


To see what is the sha for given reference (branch or master)
use the following example

git rev-parse master