Here's a git problem. I'm making a programming study review app in pure (command line) Ruby. This app allows the user to design and schedule reviews of programming tasks, manage the files in which the tasks are performed, and run the result automatically from the app. For these purposes, I don't need git when there's a single file. But most advanced and web programming tasks involve editing and using multiple files, and to manage that, I need to use git, and I'm not great with git.
In the app, the maker of these more complex "repotasks" is expected to make questions based on a git branch (of his choice) of a repo (of his choice). So I figure what this requires is that, for each repo, there is a series of branches, each of which is maintained independently of each other, and each of which is relatively stable; and the app basically checks out branches as needed to answer questions. It sounds simple...
The problems are:
After I make new branches (by hand, with
git checkout -b branch_name
) and add new files, I seem to be prevented from checking out some previous branches. For example:$ git checkout foobar_JS_enabled_missing_prompt error: The following untracked working tree files would be overwritten by checkout: display_nodename.html Please move or remove them before you switch branches. Aborting
I (think I) need to
git reset --hard
branches after a user finishes answering a question. But doing this seems to have inadvertently blanked a file I worked hard on in setting up a later branch. I think it's because I hard-reset an earlier branch in which said file was blank.
The git interaction the app does (mostly using ruby-git) so far is:
- Actually create repos and branches by hand.
- List branches for question-makers to choose from.
Checkout branches when they are chosen, using
g = Git.open("data/repos/#{repo}") g.branch(branch).checkout
Do a hard reset of a branch that a question is based on when the user starts answering the question, using:
g = Git.open("data/repos/#{repo}") g.reset_hard
I haven't done this yet, but I want to create an archive branch for each question, i.e., I want to let a question-answerer to review an old answer, then switch to the main branch for that question in order to create a new answer.
Basically, I want frozen versions of each branch, but the process (described above) seems to create unwanted interactions. I thought branches were isolated from each other automatically. What am I doing wrong? What do I need to do in order to freeze the last-committed version of each branch, regardless of what happens in other branches, while I switch frequently between branches?
UPDATE (11/18): I will leave this as a comment rather than an answer, because the question is a little obscure. I never realized that the index and tree are independent of branches. So my code actually had a few subtle bugs relating to the fact that I was letting my tree get unclean. In a couple of places, I needed to hard reset the code before letting an answerer start work on an answer, even if, most of the time, that isn’t necessary. I also needed to hard reset the code after an answerer finishes. Another thing I needed to do was to check what branch is currently checked out and switch to the right one ( I had already done this, but not everywhere I should’ve).
Seems to be working now, and I’m not able to replicate the bugs anymore.