1

TL;DR version

Files in a certain folder are cluttering my search results when I search on GitHub. I only need those files for their archivational purpose, so although I don't want to remove them, I thought I could move them to a separate branch periodically to clean up this folder in master.

Question is how to do that in such a way that it's easy, repeatable, and doesn't pollute my history too much.

Context

My (our) situation, we have a git repository that holds the current state of our data model. So it has a file called TAB_ORDER.sql, which contains the create table statement for creating the table. These files are basically generated using RedGate Schema compare.

In addition, the repository contains migration script that help us deploy changes. A pull request is expected to contain the change to the object file, as well as a migration to make it happen on the live database. So to add a column to that table, in a single PR, I would add a migration file with an alter table TAB_ORDER statement for adding a column, and I would modify TAB_ORDER.sql so the create statement in there represents the new state of the table, including the new column.

So far so good.

The problem

The problem is, I love to use GitHub to search for uses of certain database objects, because it's fast, and it allows me to search through all our repos. But my searches are polluted by all the migrations scripts. Ideally I want to exclude those from the search, but GitHub doesn't support that, and it doesn't look like it will any time soon.

So I have basically two options, apart from just sticking with it:

  • Delete the migration scripts completely.
  • Keep the migrations in a separate branch, but not in master.

I would prefer the latter, so I can actually keep my migration scripts, and search those if I want to. Deleted files are kept in history, of course, but it's not easy to find those anymore, so keeping them undeleted has preference.

My solution (that I need help with)

How can I easily move these migration scripts to a separate archive branch. Given the fact that I want developers to create a single PR with the migration and the modification, that archiving would be a separate process that I could do periodically, but I don't really know a good way to "move" files from master to a branch, basically.

Alternative solutions are welcome too, of course.

3
  • Are you using Oracle or SQL Server? I work for Redgate and it's intriguing to us that you're searching the scripts folder for object references. We're wondering whether rather than a file search this should be something we solve better in the tooling? Commented Mar 28, 2019 at 21:32
  • Yes, there are different ways to search. Files is an option, if I search just in that repo. I can even search in the database itself. But GitHub is really fast (it's quite a big Oracle database), and I use it to search other repos of other code bases too. Especially if I want to find which other projects use a certain database object, GitHub is very convenient, because we got dozens of repositories, and I don't even have all of them checked out. GitHub can search across all of them at once. It's a very useful tool if I want to check what the impact of a change would be.
    – GolezTrol
    Commented Mar 28, 2019 at 21:39
  • Understood. Thanks for posting the solution. I didn't know about -path either, so I've learned something too! Maybe we should even document this "trick" somewhere for the benefit of other users :) Commented Mar 29, 2019 at 8:54

2 Answers 2

1

Turns out you actually can exclude paths from the search results. I couldn't figure it out before, and when searching I only found evidence that it's not possible. But a colleague (thanks, Wes!) just pointed out to me that you can simply add -path to the search query to filter out a folder.

So to search for the use of TAB_ORDER in all repositories, except in the Migrations folders (fingers crossed that other repos don't have relevant search results in a folder with the same name), I can simply search for this:

TAB_ORDER -path:Migrations

Looks like the path has to be the full path (relative to the repo), so if you have a path a/b/c, you can add -path:a, or -path:a/b/c, but not just -path:c.

1

The easiest I can think of is:

Create an archive branch

git checkout -b archive

Afterwards copy those files to your new archive branch via:

git show <branch_name>:path/to/file >path/to/local/file

Now checkout your master branch again and remove your unwanted files in the master branch.

rm file

Afterwards update your master repository again

git add *    
git commit -m "removed file"    
git push origin master

Not the answer you're looking for? Browse other questions tagged or ask your own question.