Git Subtree只有一个文件或目录

时间:2014-03-11 19:10:11

标签: git bitbucket git-subtree

我使用Git Subtree如下:

git subtree add --prefix=directory_destination_path --squash git@bitbucket.org:kicaj/projectname.git master

但在路径中:directory_destination_pathprojectname.git

复制所有回购

如何仅从directory_destination_path复制到projectname.git子目录或仅复制某个文件?

修改
还有一个问题:
如何更新(自动)两个存储库中的文件更改仍然是相同的?有可能吗?

2 个答案:

答案 0 :(得分:19)

如果我理解,您似乎只想合并到不同存储库的某个目录中,并且您希望它成为存储库中的子树。我打算在project.git path_of_interest_in_project中调用感兴趣的目录,并在您的回购directory_desination_path中调用目的地。

尝试将远程project.git添加为远程,然后在本地检出其中一个分支。然后使用git-subtree split拆分您感兴趣的project.git目录。之后使用子树合并将其合并到您的仓库中。

git remote add project git@bitbucket.org:kicaj/projectname.git
git branch project_master project/master

分支project_master现在应该存储project.git repo。

的整个历史记录

然后您需要使用git-subtrees-split流程。

git checkout -f project_master
git subtree split --squash --prefix=path_of_interest_in_project -b temp_branch

现在应该有一个名为temp_branch的分支,其中只包含您感兴趣的目录。现在,您可以执行git-subtree-merge将其全部存入您的仓库。

git checkout -f master
git subtree merge --allow-unrelated-histories --prefix=directory_destination_path temp_branch

这应该在temp_branch中合并到你的主分支。

答案 1 :(得分:1)

假设您想在ref import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class Mitternachtsformel implements ActionListener { JFrame frame; JPanel panel; JPanel panel1; JPanel panel2; JPanel panel3; JTextField text; JTextField text1; JTextField text2; JLabel label; JLabel label1; JLabel label2; JTextArea textA; double aZahl; double bZahl; double cZahl; double x1; double x2; public static void main(String[] args) { Mitternachtsformel MF = new Mitternachtsformel(); MF.launchScreen(); } public void launchScreen() { //frame erstellen frame = new JFrame("Mitternachtsformel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500, 500); //font erstellen Font font = new Font("impact", 50, 50); //panel erstellen panel = new JPanel(); panel.setSize(500, 500); panel.setBackground(Color.white); //panel1 erstellen panel1 = new JPanel(); panel1.setSize(500, 500); panel1.setBackground(Color.white); panel1.setVisible(false); //panel1 erstellen panel2 = new JPanel(); panel2.setSize(500, 500); panel2.setBackground(Color.white); panel2.setVisible(false); //panel3 erstellen panel3 = new JPanel(); panel3.setSize(500, 500); panel3.setBackground(Color.white); panel3.setVisible(false); //label erstellen label = new JLabel("Geben sie einen Wert für a an: "); label1 = new JLabel("Geben sie einen Wert für b an: "); label2 = new JLabel("Geben sie einen Wert für c an: "); //textField erstellen text = new JTextField(10); text.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { panel.setVisible(false); panel1.setVisible(true); } }); //textField1 erstellen text1 = new JTextField(10); text1.requestFocus(); text1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { panel1.setVisible(false); panel2.setVisible(true); } }); //textField2 ertsellen text2 = new JTextField(10); text2.requestFocus(); text2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { panel2.setVisible(false); panel3.setVisible(true); } }); try { aZahl = Double.parseDouble(text.getText()); bZahl = Double.parseDouble(text1.getText()); cZahl = Double.parseDouble(text2.getText()); } catch(Exception ex) { } try { x1 = (-bZahl + (Math.sqrt((bZahl*bZahl) - 4 * aZahl *cZahl))) / (2*aZahl); x2 = (-bZahl - (Math.sqrt((bZahl*bZahl) - 4 * aZahl *cZahl))) / (2*aZahl); } catch(Exception ex) { } //textArea erstellen textA = new JTextArea(x1 + ", " + x2); //add- things panel.add(label); panel.add(text); panel1.add(label1); panel1.add(text1); panel2.add(label2); panel2.add(text2); panel3.add(textA); frame.add(panel3); frame.add(panel2); frame.add(panel1); frame.add(panel); frame.setVisible(true); } public void actionPerformed(ActionEvent arg0) { } } 处添加octocat git repo的setTimeout(function () { if (i >= num_frames) { return; } try { var points = "[" + array_all_snapshot[i] + "]"; console.log(points); var points = array_all_snapshot[i]; var heat = L.heatLayer(points, { maxZoom: 10 }) .addTo(map); } catch (e) { console.log(array_all_snapshot[i]); console.log(e.toString()); } i += 1; requestAnimationFrame(function () { repeatOften(i); }); }, 11 );前缀。

假设我们要使用托管在https://github.com/octocat/octocat.github.io.git上的远程服务器(注意:GitHub在以下images/命令中返回master是您指定不与命名ref关联的sha1)

从您希望将子树添加到的分支开始,让我们首先获取所需的提交历史记录并签出新分支

error: Server does not allow request for unadvertised object

接下来,让我们创建一个新的历史记录,其中仅存在我们所需前缀(fetch)下的文件。

git fetch https://github.com/octocat/octocat.github.io.git master:tmp_octocat_master
git checkout tmp_octocat_master

最后,让我们将此子树添加到所需的分支中(大概是您所在的最后一个分支,images/

git subtree split --prefix=images -b subtree_split_branch

现在,您应该在当前分支上拥有所有所需文件,并具有完整的git历史记录。

Alt压缩历史记录

有时您希望将子树中的提交压缩为单个提交。这在一定程度上不利于添加子树的目的,但是它有它的位置。以下是上述内容的一种变化形式,用于限制提取到您的存储库中的历史记录

从希望将子树添加到的分支开始:

git checkout -

注意:由于我们在下面的git checkout - git subtree add --prefix=public/images subtree_split_branch 命令中使用的是git fetch --depth=1 https://github.com/octocat/octocat.github.io.git master:tmp_octocat_master git checkout tmp_octocat_master ,因此我们在上面指定了--depth=1

--squash