开发者

A file in git associated with the repo, under revision control, but not associated with any particular branch?

开发者 https://www.devze.com 2022-12-24 11:29 出处:网络
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.

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 开发者_StackOverflow社区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

A file in git associated with the repo, under revision control, but not associated with any particular branch?


Use a different repo.

I keep a ~/org directory that emacs automatically tracks in git and syncs across my machines. All of my todos and such are in there, but it's not associated with any particular project. If I wanted one associated with a specific project, I'd make a ~/org/project.org.


Any time you want to update your todo file, you can merge it first

git checkout previousBranch todo

Note: if you don't merge, you can see the content of a todo for any branch with:

git show myBranch:todo

If your todo file is at the root directory of your repository, it will work from any path, since the path used by git show is an absolute one from the top directory of said repo.

That way you can:

  • see tasks that only make sense in one branch
  • have a script concatenating the content of all the todo versions for all the branch (git branch)
0

精彩评论

暂无评论...
验证码 换一张
取 消