Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull from another repository without history

I'm here because : I try to connect my repository to another in order to keep "up to date" but I'm trying not to pull the whole history of the other repo...

To explain, I use Laravel 5 (https://github.com/laravel/laravel) and I have created my own master (which is a fork of laravel/v5.0.1) to customize some things inside (like a css framework, some generic layouts, etc.) -> call it "azurky-repo/master"

And now I feel like updating my repository with lastest commits of laravel/master but each time I pull from laravel/master, my "git log" is full of commits (about 4400) and I don't want this. (I'm a kind of maniac guy who wants a clean repository and a lot of control over everything ^^).

In an ideal world, I would like to update only the files and then just make one commit with a message like 'Update from Laravel/master'. Without any other extra history entry or refs that I don't need at all.

Tried without success :

git pull --depth 1 laravel master

I still have an extra history entry... (the last laravel/master commit message and didn't succeed in amending... maybe missed something)

Someone has an idea (or am I the only mad guy to try a thing like this..)?

P.S :

To clarify, I would like to have the same result as if I :

  • clone the laster version of my repo (azursky-repo/master)
  • download all the updated files from laravel/master
  • overwrite my repository with this files
  • merge manually each modified files
  • And then push to azursky-repo/master with "Update from laravel/masgter"

The matter is in fact I'm not masochist and don't want to bypass the merging ability of git... ^^

So I feel like having, finally, this history :

  • Rev1 : "Inital commit - Laravel v5.0.1"
  • Rev2 : "Implementation of Foundation5 / SASS / Gulp"
  • Rev3 : "Update from laravel/master"

In place of :

  • Rev1 : "Inital commit - Laravel v5.0.1"
  • Rev2 : "Implementation of Foundation5 / SASS / Gulp"
  • 4400 commits from Laravel/master
  • Rev4403 : "Merge conflict from updating laravel/master" (something like this)

Do you see what I hope ?

like image 649
Azsky Avatar asked Mar 08 '15 23:03

Azsky


People also ask

How do I copy a git repository without history?

i.e. if you just want the latest commit use git clone --depth 1. branch is the name of the remote branch that you want to clone from. i.e. if you want the last 3 commits from master branch use git clone --depth 3 -b master. repo_url is the url of your repository.

How do you commit without committing history?

Create a new orphan branch, named <new_branch>, started from <start_point> and switch to it. The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.

Does git clone get all history?

Cloning an entire repo is standard operating procedure using Git. Each clone usually includes everything in a repository. That means when you clone, you get not only the files, but every revision of every file ever committed, plus the history of each commit.

Does git archive include history?

The available list of formats can be retrieved with the git archive --list command. But the Git archive command includes only the files, not the history of those files.


1 Answers

Finally got it !

The answer is just a simple :

git reset HEAD

Sorry I'm really new to git so I found the solution this afternoon after reading questions about this kind of subjects. Didn't understood everything about indexes, now it's better =)

So from beginning I have a fresh repo with just an initial commit :

git clone git@mygitserver:myuser/myrepo
git log
commit 1
   Initial commit - Laravel v5.0.1 

Then I pull from laravel/master

git remote add laravel https://github.com/laravel/laravel.git
git pull laravel master
git reset HEAD
git add --all
git commit -m 'Update from laravel/master'
git log
commit 2
    Update from laravel/master
commit 1  
    Initial commit - Laravel v5.0.1

That seems OK, then I make an other modif. to to be sure :

git rm -rf resources/assets/less/
git add --all
git commit -m 'Suppression de bootstrap'
git log 
commit 3
    Suppression de bootstrap
commit 2
    Update from laravel/master
commit 1  
    Initial commit - Laravel v5.0.1

N.B : I write commit 1/2/3 to simplify of course

And then to be extra-sure :

git push origin master

And check on the repository web page

http://i.stack.imgur.com/7XMzb.jpg (sorry haven't the right to put the img)

That's OK for me =)

Finally I like the way git works =)

like image 186
Azsky Avatar answered Oct 29 '22 21:10

Azsky