1

Is it possible to delete, for example, an entire directory from a previous commit, and make the resulting changes "visible" in all current/future branches? I forgot to exclude the target/ directory early on in development, and now I am trying to eliminate it entirely from the whole repo.

I already deleted it from the master branch, do I have to repeat that for every branch I've created? Or is there a "better" solution?

Win32
  • 149
  • 1
  • 9
  • While cherry-picking (@mrks) and daggy-fixes (@j6t) are excellent solutions to your problem, they might not completely solve it. They do help if the directory and the files in it were added once and never changed. E.g. if the files were changed or new files were added in some branches then you might have to do some extra work. – EricSchaefer Dec 19 '20 at 08:56

2 Answers2

2

Use cherry-pick to apply the same commit (i.e., the commit that deleted the target/ directory) on a different branch.

You could iterate over all branches to do it automatically, but assuming a single digit number of branches, this is not worth automating.

You only need to do this for existing branches. For future commits that branch off master, this will automatically part of the history.

mrks
  • 8,033
  • 1
  • 33
  • 62
2

Create a new branch that begins at the very commit that added the directory, make a commit that removes the directory, then merge that new branch into every other branch that has the unwanted directory.

j6t
  • 9,150
  • 1
  • 15
  • 35
  • Note, though, that commits don't really "add a directory": they just have, in them, a file whose name requires the OS create a directory to hold it. :-) There can also be issues with varying sets of files, each of which requires the directory name to exist, but with the file-set being different in different commits to which you intend to merge this commit. Overall though this is usually the way to go. – torek Dec 18 '20 at 14:28