1

I have created a new branch and made changes to folder X. At some point we realized that we need to keep the old methodology for several purposes. Now I would like to enter the altered folder under a new name (let's call it X_Y) to the master folder, so that master will have both X and X_Y.

I'm new to git and mainly doing data related things locally normally, so my first attempt didn't take into account git info - I copy pasted the folder from the new branch to a different local folder, then I renamed it to X_Y, and pasted X_Y folder to the master with the new name. However now it doesn't work from master branch - one error example: TypeError: expected str, bytes or os.PathLike object, not NoneType - it has no such issues in the new branch with the old name. I understood that it is expected not to work as it is wrong to do it this way. How would I go about doing that simply and quickly?

isherwood
  • 58,414
  • 16
  • 114
  • 157
HermanK
  • 309
  • 1
  • 10
  • 1
    Technically, a *branch* has no folders at all. A branch lets you (and Git) find *commits*. Commits then hold files (but not folders, just files). Git will create a folder when necessary: if commit `H` (some hash ID) has a file named `path/to/file.ext`, Git knows to make directories `path` and `path/to` so that the computer's demand that `file.ext` be created within `to` that is within `path` be satisfied. But in each commit, Git just stores *all the files* (no folders), with slashes in their names. – torek Oct 31 '21 at 11:55
  • 2
    The error message you show is from Python and has nothing at all to do with Git; it's not clear what is going on. Git is storing (and extracting) commits: a branch name like `master` refers to some particular commit, and that commit holds the files, so that `git checkout master` extracts the files from that commit. – torek Oct 31 '21 at 11:55
  • @torek Thanks for the explanation. I don't know if the error is related, I just know that I don't get this if I run the functions when the new branch is checked out. But when I copy pasted the a directory to a local place, changed name, and then uploaded it to git master with the new name, those same functions don't work and show the error from above. – HermanK Nov 01 '21 at 10:47
  • Your Python code probably opens and reads particular files by particular names as controlled by other files with other names, so that if you don't have all the names lined up, you get a runtime error like that. Better Python source code would notice that something is amiss and give you an error message like "file XYZ says I should read info from section ABC, but section ABC is missing from file GHI" or whatever. – torek Nov 01 '21 at 10:55
  • Given the dynamic nature of Python, it's very easy to set things up so that users can shoot themselves in the foot. The only way to know for sure is to inspect the Python source code. – torek Nov 01 '21 at 10:56
  • @torek but again, disregarding the python error. Is the way I copy pasted the package locally, renamed and uploaded to master, is correct or should be done differently? – HermanK Nov 01 '21 at 12:53
  • 1
    You have not showed yourself to make any *Git* errors. But you also have not showed as having run even a single Git *command* here: you talk about "pasting folders", which is a thing one does in various GUIs; those GUIs implement these operations by modifying files in trees. Git is about *commits*, not about files in trees. (We use files-in-trees to work with multiple files, and then use various Git commands to make commits *using* these files, but you haven't shown yourself doing the latter.) – torek Nov 01 '21 at 12:56
  • It didn't work because during the copy process, the `__init__.py` files in some of the sub directories didn't get copy pasted. – HermanK Nov 02 '21 at 09:26
  • 1
    That makes some sense (empty `__init__.py` files are required to make packages out of directories [in the old style](https://stackoverflow.com/q/448271/1256452)) but the fact that the GUI left these files out seems like very bad behavior on the part of the GUI. – torek Nov 02 '21 at 09:29

1 Answers1

0

Seems that the described process is valid in theory, although in practice some of the files weren't copied in the process, specifically the __init__.py files in the subdirectories. After I added those manually, everything worked.

HermanK
  • 309
  • 1
  • 10