RSS

Category Archives: Repositories

Git Keep only recent commits in history

Ever faced a situation to cleanup the history in git where you do not need to retain very older commits in history that you never will rollback or do any operation??

I faced this where i need only recent 700 commits in my history.

Here is the work around i did.

Let branch1 be the one which has some 5k+ commits committed years ago

Now i need branch2 with just recent 700 commits in the history, that is the 700th commit from present to past should be the initial one of the repo

I used the fast-export and import feature of git along with the linux sed command combined together for this

git fast-export branch1~700..branch1 | sed “s|refs/heads/branch1|refs/heads/branch2|” | git fast-import

  1. Use fast-export to export the recent 700 commits in branch1 branch
  2. sed – way to create a new branch called branch2 out of branch1 branch
  3. Import the exported 700 commits alone into the branch2 branch

Now you will have your desired branch2 in your local repo which you can push to github

 
Leave a comment

Posted by on October 9, 2014 in Git

 

Tags: , , ,

Git-Reset commit in local branch

I have committed a file in my local master branch, I am trying to push that file to the remove master branch, I got the below mentioned error.

$ git commit -m "file committed" [File Name]
$ git pull origin master

Error:

! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘git@git.company.com:projectName.git’

After that i tried to pull the content form master branch. I got conflict error.

$ git pull origin master

Error:

CONFLICT (content): Merge conflict in [Conflicted File with path]
Automatic merge failed; fix conflicts and then commit the result.

I just reset my local branch with the last committed version.

$ git reset --merge [Prior Git Versions]

Pull the content from the master branch.

$ git pull origin master

Its working fine now.

 
Leave a comment

Posted by on March 19, 2013 in Git, Repositories

 

Tags: , ,

Git revert to a particular commit

Suppose your git head points to the latest commit in the branch say, master.

First make your head point to the older version you need to revert by using the commit id from github

git reset –hard <commitid>

Then push to github using

git push -f origin <commitid>:master

Here the branch we use is master

 
Leave a comment

Posted by on November 16, 2012 in Git

 

Tags: , , , ,

Basic steps for git set up

Steps-1:

sudo apt-get install git-core

Steps-2:

git config --global user.name "your git hub username”
git config --global user.email "your git hub email"

Steps-3:

ssh-keygen -t rsa -C "your git hub email"

Steps-4:

ssh-add
It will suggest a default file name id_rsa.pub, accept that
Give a passphrase when it asks one. This will be your passphrase to 
give whenever you commit for first time after starting the machine.

Steps-5:

cd to that file path (cd ~/.ssh) and open that file 
(gedit id_rsa.pub) You will see the ssh key like this,
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvBcneUfRDJm2TYL4MrX9UrBaFus4ebZ
+hvS3SfwIe4Ydn1f8sQ7q4/Hb0l4NB0/yRn3yjJuj5IyFw0QRq1sLUErQAHMKQnJZUO
MsK044MbymF2d6DOExZIvgm4lXxSKeB3JBge+3lPmXatuJbHAQXMDa2kdBRy1ICCbr3
48yZRAAyizEyzSDT3ireFnF5PNxt4E0avx1QrCVZmPX6T6LZ21J5+ObwdvtPomOTOYo
iknrScRrPmTUyG+g6ZdezQhKxOCBd8XKW5NYmcaz4olCVtCwsIuCGpv0Hrh0bpxj14k
Kmv1KVKOA89vuzWtoeGWfZ2xQSSsZhaTTOhrFWV+ImQ== test@test.com

Steps-6:

Login github.com, go to your profile, click Edit your profile, 
then SSH Keys,Give any title and copy paste the ssh key from 
your file, without the email id, that is up to ==
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvBcneUfRDJm2TYL4MrX9UrBaFus4ebZ
+hvS3SfwIe4Ydn1f8sQ7q4/Hb0l4NB0/yRn3yjJuj5IyFw0QRq1sLUErQAHMKQnJZUO
MsK044MbymF2d6DOExZIvgm4lXxSKeB3JBge+3lPmXatuJbHAQXMDa2kdBRy1ICCbr3
48yZRAAyizEyzSDT3ireFnF5PNxt4E0avx1QrCVZmPX6T6LZ21J5+ObwdvtPomOTOYo
iknrScRrPmTUyG+g6ZdezQhKxOCBd8XKW5NYmcaz4olCVtCwsIuCGpv0Hrh0bpxj14k
Kmv1KVKOA89vuzWtoeGWfZ2xQSSsZhaTTOhrFWV+ImQ==

Steps-7: After saving that, come to command line and clone your repository like git clone <repo url> the repo url will be visible when you click the repo link in git hub after logging in.

 
Leave a comment

Posted by on October 1, 2012 in General, Git, Ubuntu

 

Install Subversion in centos

1. To see the list and its availablity

>yum list available | grep subversion

It will show the list of availablity,

2. To Install the latest version

>yum install subversion

3. To see the version after installation

>svn –version

 
 

Tags: , , , , , , , , , ,

Git – Pull out a remote branch

This is the command to pull out a remote branch in git to local

git checkout –track -b mybranch origin/remote-branch-name

 
Leave a comment

Posted by on April 19, 2011 in Git, Repositories

 

Tags: ,

Some more GIT commands

1. TO CREATE A NEW BRANCH
git branch [name of your new branch]

2. TO SWITCH TO THIS BRANCH
git checkout [name of the new branch]

3. TO CREATE A BRANCH AND SWITCH TO THE BRANCH IN ONE MOVE:
git checkout -b [name of new branch]

4. TO PUSH THE NEW BRANCH TO A REMOTE REPOSITORY
git push origin [new-branch]

5. TO MERGE YOUR NEW BRANCH INTO THE MASTER BRANCH
First, switch back to the master branch:
git checkout master
Then merge “xyz” branch to master
git merge xyz

6. TO PULL A NEW BRANCH FROM A REMOTE REPOSITORY
git fetch origin [remote-branch]:[new-local-branch]

7. TO MAKE SURE THAT YOUR NEW BRANCH GETS CHANGES FROM THE MASTER BRANCH (WHERE EVERYBODY ELSE IS WORKING) USE THE REBASE COMMAND
git rebase master

8. TO SWITCH TO ANOTHER BRANCH
git checkout [name of the branch you want to switch to]

9. TO DELETE A BRANCH THAT IS NOT USED ANYMORE, but already merged into the current branch. (TO CLEAN UP)
git branch -d [name of branch you want to delete]

10. TO DELETE AN UNMERGED BRANCH
git branch -D [name of branch you want to delete]
 
Leave a comment

Posted by on January 11, 2010 in Git, Repositories

 

Tags: , , , ,

Taking dump from svn repositories

Ever faced the situation to take a backup from the svn repository? I faced recently and finally got up with the correct procedure. Here is the complete profile of my experience.

After going inside your remote server by ssh, get into the path where your repository is set and then use the below command to take the dump.

svnadmin dump original_repository_name > dump_name_chosen_by_you

Use . in place of original_repository_name if you are inside the repository itself.

To take the dump of your mysql database present,

Let the username of your mysql be xxx and password be yyy

mysqldump -uxxx -pyyy database_name > dump_name_chosen_by_you.sql

And after taking the dump and the dump file successfully created, there may be a need to compress the dump file and i used tar.gz compression.

tar -zcvf compressed_name_chosen_by_you.tar.gz dump_name_created_before

To compress a full working directory,

tar -zcvf compressed_name_chosen_by_you.tar.gz full_path_of_the_directory

z – use gzip for compression

c – create archive

v – display the progress while doing archive

f – file name of archive

If want to use zip,

zip compressed_name_chosen.zip file_name

Then for taking a copy of  the compressed files from the remote into your local disk,

From your command prompt,

scp user_name_of_remote_server@server_ip:path_of_compressed_file_with_ext .

In my case the extension was tar.gz

And make sure not to miss a dot after the command leaving one space

The file will be copied into the location from where you did the command.

Then to extract the files in your local,

tar -zxvf compressed_archive_name.tar.gz

x- Extract


 
Leave a comment

Posted by on December 10, 2009 in Subversion(svn)

 

Tags: , , , , , , , ,

GIT – Version Control System

Here are the few commands in git repository system that we can use.

To install git in ubuntu:

sudo apt-get install git


To get a clone from a repository:

git clone <repository url>


To add  new file(s) created in local to the repository:

git add <file-name1> <file-name2>..

git commit -m “comments about the adding files”


To view the changed file:

<go_to_project_directory>

git status


To commit some changed files:

git commit -m “comments about the commit” <file-name1> <file-name2> <file-name3>….


Then push all the changes made so far into the repository after add and commit:

git push


Remember to pull the latest version from the repository into local before committing anything to avoid problems when merging:

git pull


 
Leave a comment

Posted by on December 4, 2009 in Git

 

Tags: , , ,