0

I'm currently having a bit of trouble with a project I'm working on in Unity. I'm still kinda new to both git and unity so some pointers would be great. One of my team members added the entire Unity project onto github, so every single file in the Unity project's directory is currently being tracked. There are two things I'm looking to do:

  1. Currently, my team member has a dependency pointing to an absolute path to an external library on their machine. I changed the absolute path to the external library on my machine, but I do not want to push that change up (forever). I added it in the .gitignore file, but it still showed up since it was being tracked. I then did a git rm --cached <file> and successfully removed it from being staged, and pushed the folder to the remote branch I'm on. I'm worried that when I merge it with master, the file will be deleted from the master branch, so I was wondering if this was in fact the case?

  2. This is more Unity specific, but every time I open Unity, a bunch of internal files in the project change. I did the same process as above (git -rm --cached ) and when I pushed it up to my remote branch, they didn't show up. Same thing as 1. but will these folders be deleted in the master branch if I merge?

If the files do get deleted when merged, is there a way to prevent this?

  • 1
    If you added *all* of the files then you have a problem. You need to use a `.gitignore` file to filter out files that are not meant to be checked in. Here's one that should get you started: https://www.toptal.com/developers/gitignore/api/unity If you've done things correctly you should not have random files being changed when you open the project. – Retired Ninja Mar 08 '21 at 00:34
  • That link is super helpful thanks! Also, unfortunately, I didn't add all of the files into the master branch, it was one of my teammates that did. Is there any way to remedy this? – Praneetmek Mar 08 '21 at 00:45
  • Well, there's the easy way and the hard way. If you don't need the history make sure you have a clean copy of the repo, rename the master branch, then make a new master and add the files with the .gitignore in place so you don't add what you don't want to. The harder way is manually delete all the files the .gitignore would ignore and commit that, then add the ignore and commit that. When others pull it should delete the files that will be ignored in the future. A `git clean -fxd` should get any leftovers. – Retired Ninja Mar 08 '21 at 01:52
  • 1
    `git clean -xfdn` would be good to test it. It only prints out the list of things that **would** get removed but doesn't yet do it ;) after rechecking remove the `n` and run the command again – derHugo Mar 08 '21 at 06:03
  • Actually you don't even have to create a new master branch! Simply pull/checkout the master, add the .gitignore, commit it .. in the future these files will be ignored .. the past most probably doesn't matter ;) This way you keep all history (including that mistake :'D ) – derHugo Mar 08 '21 at 06:06
  • @derHugo Whenever I have tried to do that it just ends in sadness. `git clean` won't delete the newly ignored files because they were committed in the past and if you delete them manually they still show up as changes. It's possible there's a way around that, I'm no git master, but the only reliable way I've found is to make sure anything you want to ignore is already gone. – Retired Ninja Mar 08 '21 at 23:18
  • 1
    @RetiredNinja yes that's true .. `-x` only removes **untracked** files .. ones that have been committed before are already tracked. But together with `git rm --cached` that OP tried it should remove these from being tracked as well. So the order should probably be: 1. Create the `.gitignore` 2. Commit the `.gitignore` 3. Call `git rm --cached *` 4. `git add *` (will get some warnings about ignored files) 5. commit these changes -> removing of files. – derHugo Mar 09 '21 at 07:31

0 Answers0