如何将github repo中的文件转换为gist

bil*_*l_e 24 git gist github

我想做的是这个问题的反面.我在github仓库中有一个文件夹,其中包含我想继续进行更改的d3可视化.很高兴有一个这个仓库的"gist"版本来显示bl.ocks.org上的可视化,我可以在我对它们满意之后将更改推送到主要仓库.

另一个类似的问题在这里,但答案描述了步骤gist - > bl.ocks.org.我不确定步骤githup repo - > gist.完成此任务的最佳方法是什么?

Ion*_*zău 23

首先,请注意Gist不支持目录.要将存储库导入gist,请执行以下步骤:

  1. 创建一个新的要点并在本地克隆它(用您的Gist id替换虚拟ID):

    git clone git@gist.github.com:792bxxxxxxxxxxxxxxx9.git
    
    Run Code Online (Sandbox Code Playgroud)
  2. cd 到那个gist目录

  3. 从GitHub存储库中拉取并合并:

    git pull git@github.com:<user>/<repo>.git
    
    Run Code Online (Sandbox Code Playgroud)
  4. 推动您的更改

    git push
    
    Run Code Online (Sandbox Code Playgroud)

再次注意,如果您有目录,则必须删除并提交它们:

rm -rf some-directory
git commit -m 'Removed some-directory' .
Run Code Online (Sandbox Code Playgroud)

使用上述步骤,将保留项目历史记录.如果您不关心历史记录,可以随时按下Gist中的文件.假设您有一个包含多个文件夹的存储库,并且您希望每个文件夹都创建一个Gist.您将重复以下步骤(或脚本可以执行此操作):

git clone git@gist.github.com:<gist-id>.git
cd <gist-id>
cp ../path/to/your/github/repository/and/some/folder/* .
git add .
git commit -m 'Added the Gist files' .
git push
Run Code Online (Sandbox Code Playgroud)

Gist与GitHub的工作方式不同:

Gist是一种与其他人共享片段和粘贴的简单方法.所有要点都是Git存储库,因此它们可以自动进行版本化,可分叉并可从Git中使用.

但是,如果您尝试在Gists中推送目录,则会从远程获取错误:

$ git push
Counting objects: 32, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (21/21), done.
Writing objects: 100% (32/32), 7.35 KiB | 0 bytes/s, done.
Total 32 (delta 10), reused 0 (delta 0)
remote: Gist does not support directories.
remote: These are the directories that are causing problems:
remote: foo
To git@gist.github.com:792.....0b79.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@gist.github.com:79.......9.git'
Run Code Online (Sandbox Code Playgroud)