git - 如何将 GitHub 存储库中的文件转换为 Gist

标签 git github gist

我想做的是 this question 的逆运算.我在 GitHub 存储库中有一个文件夹,其中包含我想继续对其进行更改的 d3 可视化。最好有一个这个 repo 的“Gist ”版本来在 bl.ocks.org 上显示可视化效果,我可以在对它们感到满意后将更改从主要 repo 推送到 when。

另一个类似的问题是here ,但答案描述了步骤 Gist -> bl.ocks.org。我不确定步骤 githup repo -> gist。实现此目标的最佳方法是什么?

最佳答案

首先,请注意 Gist 不支持目录。要将存储库导入 Gist ,请按照以下步骤操作:

  1. 创建一个新的 gist 并将其克隆到本地(用您的 Gist id 替换虚拟 id):

    git clone git@gist.github.com:792bxxxxxxxxxxxxxxx9.git
    
  2. cd 到那个 gist 目录

  3. 从您的 GitHub 存储库中 pull 并 merge :

    git pull git@github.com:<user>/<repo>.git
    
  4. 推送您的更改

    git push
    

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

rm -rf some-directory
git commit -m 'Removed some-directory' .

使用上述步骤,将保留项目历史记录。如果你不关心历史,你总是可以在你的 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

Gist 与 GitHub 的工作方式不同:

Gist is a simple way to share snippets and pastes with others. All gists are Git repositories, so they are automatically versioned, forkable and usable from 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'

关于git - 如何将 GitHub 存储库中的文件转换为 Gist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32954183/

相关文章:

git - Gist:如何将图像上传到 Gist?

Github 比较来自不同用户的两个不同的存储库

git - 如何用空目录克隆 CVS 存储库

Git:在 git 中克隆远程存储库时无法解决主机 github.com 错误

windows - 如何在 Windows 上存储 Git 的身份验证凭据?

html - Github 要点页面不会在 iframe 中加载

visual-studio - 在一次提交中更改类和文件名时的 Git 重命名检测

git - 如何在从钩子(Hook)/接收后 checkout 时设置 git 文件的所有者和组?

python - 使用工作流在 github 中对 databricks python 代码进行 flake8 linting

git - 将 gist 与 github 存储库链接,但将不同的文件推送到每个