2

So, I am new to Git. I know how to make repos, commit, push, merge etc.

But I have a question that might sound silly.

I have a script that runs at a specific time everyday.

When I create a new branch to develop new features, how can I continue running the old file?

Example python3 file_v1

In my pre-Git days, I would have simple creating file_v2 and kept file_v1 running. I know this archaic. But would appreciate a solution.

maximusdooku
  • 5,242
  • 10
  • 54
  • 94
  • @sajibkhan But that would only work if my new features take less than one day to develop (it takes more). Meanwhile, the code needs to continue running everyday. – maximusdooku Apr 08 '17 at 17:43

2 Answers2

1

You have only two choices:

  1. Don't run the file out of that Git repository (or at least work-tree).

    This may mean running the file out of no repository at all, or out of a different git clone of the repository (in a different directory on your system), or using git worktree add to make a separate work-tree that stays on its own separate branch.

    In all three cases, the path to the file is not /path/to/repo/file but rather /path/to/somewhereelse/file or similar. So regardless of what happens to /path/to/repo/file, the periodic command runs something else.

  2. Keep the "stable" file around under an alternate name, such as file_not_being_developed.

    That way, running /path/to/repo/file_not_being_developed always runs the stable version, even though all the files around it are changing.

    Note that you can have this file committed (a copy in each commit in every branch), or .gitignore-ed and never committed (so that there is no copy in any branch, it's just a work-tree-only file). How and when you update it is thus up to you.

Method 2 is probably inferior (I wouldn't use it myself).

torek
  • 448,244
  • 59
  • 642
  • 775
  • So, this is not different than file_v1, file_v2 then. I would have thought git had an inbuilt solution for this. But thanks for the clarification. – maximusdooku Apr 08 '17 at 17:45
  • Correct. If you wish to *extract* one specific file from Git, you can `git show :`. But you will have to extract the file from somewhere (e.g., from `master`) and write it to some stable name that your cron job, if it is a cron job, can find—or have your cron job extract it to a file, then run it, which amounts to the same thing. – torek Apr 08 '17 at 17:47
  • I think I'll just make a different clone and run it. Seems uncomplicated. And whenever I update the main branch, I sync it. – maximusdooku Apr 08 '17 at 17:48
  • 1
    That's how I'd do it; or I would install (setuptools etc) the file into a system location, and update the install as needed. – torek Apr 08 '17 at 17:49
  • Thank you. Very helpful. – maximusdooku Apr 08 '17 at 17:54
0

You can use git hooks

post-checkout This hook is invoked when a git checkout is run after having updated the worktree.

It is also run after git clone, unless the --no-checkout (-n) option is used. The first parameter given to the hook is the null-ref, the second the ref of the new HEAD and the flag is always 1.

This hook can be used to perform repository validity checks, auto-display differences from the previous HEAD if different, or set working dir metadata properties.

Its exactly what you asked for :-)

When you checkout branch write out a script which will execute what you want (cronjob for example) and pass it the desired parameters.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • I don't know about git hooks. Could you please give an example on how I would run a particular file? – maximusdooku Apr 08 '17 at 17:46
  • You simply create a file and run your script inside. here is a sample hook: http://stackoverflow.com/questions/35400416/what-are-some-more-forceful-ways-than-a-gitignore-to-keep-force-files-out-of/35400472#35400472 – CodeWizard Apr 08 '17 at 17:49