git中的文件与repo相关联,在版本控制下,但不与任何特定分支关联? [英] A file in git associated with the repo, under revision control, but not associated with any particular branch?

查看:148
本文介绍了git中的文件与repo相关联,在版本控制下,但不与任何特定分支关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为todo的文件



这是我想为这个项目做的事情列表。



我希望这个文件与我的git仓库相关联。



我希望这个文件有不同的版本,



但是,我不希望它与特定分支关联。例如:


  1. 在分支主文件上。

  2. 创建一些基本的ToDo项目

  3. 分支dev1

  4. 向待办事项列表添加更多内容

  5. 从主分支dev2。 b $ b
  6. 在待办事项列表中添加更多内容

  7. 现在,我对待办事项文件进行了不同版本的修改。

我只希望有一个todo文件 - 这可能吗?这有意义吗?我是否滥用todo?

解决方案

另一个诀窍是使用独立的分支在您的项目的子树中检出Junio Hamano(当前的Git维护者)使用Git的 todo 。食谱:

pre $ $ $ $ c $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ META

您现在可以在中创建待办事项列表 META /

  $ cd META / 
$ echo'* Item 1'> todo.org
$ git add todo.org
$ git commit -m'TODO文件的初始版本'
[master(root-commit)64748ba] TODO文件的初始版本
1个文件已更改,1个插入(+),0个删除( - )
创建模式100644 todo.org

让我们将分支名称更改为 meta ,然后将其推回到主存储库:

  $ git branch -m meta 
$ git push .. meta

您必须记得在每次提交之后将分支推回;



META / 现在显示为主存储库中未跟踪的文件;让我们在本地忽略它:

  $ cd .. 
$ git status
#(显示META / as未跟踪)
$ echo META />> .git / info / exclude

您现在可以随意切换分支, META / 将保持不变 - 只要您切换到的分支不包含冲突路径。



主存储库现在包含一个额外的完全独立的分支,它可以像项目的其他任何部分一样进行推送和拉取:

  $ git分支
* master
meta
$ gitk --all

< img src =https://i.imgur.com/8CXzh.pngalt =Screenshot>


Say I have a file called: "todo"

It's a list of things I want to do for this project.

I want this file associated with my git repo.

I want there to be different revisions of this file,

however, I don't want it associated with particular branches. For example:

  1. On branch master.
  2. Create some basic ToDo items
  3. Branch "dev1"
  4. Add more stuff to todo list
  5. Branch "dev2" from master.
  6. Add more stuff to todo list
  7. Now, I have different revisions of the todo file lying all around.

I just want there to be one "todo" file -- is this possible? Does this make sense? Am I misusing todo somehow?

解决方案

Another trick is to use an independent branch, checked out in a subtree of your project, as Junio Hamano (the current Git maintainer) does with Git's todo. Cookbook:

$ cd project/
$ git branch
* master
$ git init META

You can now create your "To Do list" and other files in META/

$ cd META/
$ echo '* Item 1' > todo.org
$ git add todo.org
$ git commit -m 'Initial version of TODO file'
[master (root-commit) 64748ba] Initial version of TODO file
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 todo.org

Let's change the branch name to meta, too, and push it back to the main repository:

$ git branch -m meta
$ git push .. meta

You will have to remember to push the branch back after each commit; setting up a post-commit hook may be in order.

META/ now shows up as an untracked file in the main repository; let's ignore it locally:

$ cd ..
$ git status
# (Shows META/ as untracked)
$ echo META/ >> .git/info/exclude

You can now switch branches at will, and META/ will stay untouched—as long as the branch you are switching to does not include a conflicting path, of course.

The main repository now contains an additional, totally independent branch, which can be pushed and pulled as any other part of your project:

$ git branch
* master
  meta
$ gitk --all

这篇关于git中的文件与repo相关联,在版本控制下,但不与任何特定分支关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆