2017-06-22 64 views

回答

0

它对于重要的文件可能有点尴尬......但这里有一个策略来创建你的新回购没有这个文件。你将能够从原始回购中获得回报,但是如果你推回去(或以其他方式),它会从原始回购中删除文件:(这是因为git在提交时运行,而不是单个文件。

首先要与特定分支中的文件一个新的回购/承诺:

# clone the repo into a new repo (just making it locally for now) 
git clone <url> newrepo 
# Move into the repo 
cd newrepo 
# Checkout the commit you want (e.g. a branch name called "mybranch") 
checkout mybranch 
# Delete the .git folder - this changes it from a cloned repo to just a bunch of files 
rm -rf .git 
# Now make this folder into a new repo 
git init 
# Now add this "pile of files" into the repo 
git add . 
# First commit 
git commit -m "First commit created from repo <url>" 

现在删除你想摆脱的文件(之前还是可以的做到这一点,如果你没有第一次提交想要在历史中):

git rm somefile 
git commit -m "removed unwanted file" 

现在添加一个远程(calle d同步或任何你想要它)到原始网址

git remote add sync <url> 

所以,现在你可以做从原始回购拉。但是,你必须小心,不要推回你的“重要文件”。这里的问题是,你在一个仓库中做的任何事情都会被同步到另一个仓库(所以如果你把你的更改推回远程“同步”(原始仓库),那么它会推动“已删除”文件。

再次 - 如果您将文件添加到.gitignore,一旦您同步,这将在两个回购站中找到...因此,也许您需要将这一个重要文件完全粘贴到单独的回购站中,并且用户需要克隆,如果他们需要它...

注意:在新的回购使用git pull sync mybranch在从原来的回购/ mybranch更改合并

注意:当你这样做拉(如上),你会看到你的本地历史树与th合并e远程同步回购的历史树。因此,在第一次拉动之后,您仍然会在分支中看到只有2个提交,但您也会看到(使用说git log --graph --all --decorate --oneline从远程“同步”树。