简体   繁体   中英

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..)?

PS :

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 ?

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

NB : 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 =)

This may be a bit of a "hack" way to do it. But, you could just git pull from that main repo, then rm the .git files in the folder, then git init and then git push -force to your repo version each time you wish to pull from the main repo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM