What’s the Best Way to Filter Commits in a Git Repository?

0
3
Asked By CuriousCoder23 On

I'm working on a deployment pipeline that requires filtering certain commits from our release branch based on their commit hashes. We currently manage this by maintaining a text file that lists folder names alongside their respective commit hashes. When we need to filter the code, a script generates a new branch, deletes everything but the index.html file and the .git directory, then checks out each folder we want based on the hashes from our text file. The downside is that this new branch loses its commit history, complicating tasks like merging if bugs are found during testing or comparing branches later on. I'm looking for better strategies to filter code we don't want to deploy to production, other than simply holding off on merges until we're ready to deploy.

4 Answers

Answered By DevFlowExpert On

Your setup sounds like it could benefit from adopting a proper Git flow. Typically, you’d have a master branch for production, develop for ongoing work, and a release branch for finalized features. This way, you can keep merging fixes back where they're needed without losing history. Feature flags can also help you control what gets deployed without stripping out any code.

Answered By DeployMaster99 On

Considering your situation, if you’re dealing with a monorepo, it might be worth looking into Git cherry-pick to preserve commit history. It can be a bit tricky to set up initially, but it really saves you from losing track of what changes were made.

Answered By CodeNinja88 On

Honestly, you might want to reconsider your approach altogether. Have you ever tried using feature flags? It's all about controlling what gets executed rather than worrying about which commits are in your branch. Think about managing your deployment pipeline in a way that focuses on execution rather than the code itself.

Answered By TechSavvy123 On

It sounds like you're taking an overly complicated approach. Have you thought about using Git submodules? Keeping each folder in a separate repo could offer a cleaner solution. Also, your main branch should be deployable as is, so this method seems pretty intense for what it needs to accomplish.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.