Is there a way to control what gets into a GitHubs zipball? - github

Every GitHub repo has the Download ZIP button, but is there a way to control what gets into the final zipball. For example we do not need and hidden files there, or even - unit tests.

Excerpt from Pro Git book:
You can tell Git not to export certain files or directories when
generating an archive. If there is a subdirectory or file that you
don’t want to include in your archive file but that you do want
checked into your project, you can determine those files via the
export-ignore attribute.
For example, say you have some test files in a test/ subdirectory, and
it doesn’t make sense to include them in the tarball export of your
project. You can add the following line to your Git attributes file:
test/ export-ignore
Now, when you run git archive to create a tarball of your project,
that directory won’t be included in the archive.

Related

MSIX installer project - which files to commit to repository?

I've created an MSIX installation project for my WinForm app, and now I'd like to commit it to my repository (git). I can't figure out which files are essential and which are now.
I assume I should commit .wapproj, <my public key>.pfx, Package.appxmanifest and the whole Images folder.
I know I shouldn't commit .user or obj files.
What do I do about bin and BundleArtifacts folders and why?
You can look at a repo on such as this Build demo to see which files should be included in source control. Essentially it is the .wapproj and the .appxmanifest files, plus the images (and then of course the actual app source code).
You shouldn't include the .pfx file since that also includes the private key used to sign the package.

.gitignore not ignoring a folder within a directory

It seems a straightforward one, but having researched multiple ways to do it, I can't gitignore a folder within a directory.
I have a root directory which contains all of my code in it. Because it has some back-end NodeJS stuff in it, it has a 'node_modules' folder which contains hundreds of files. As a result, when I try to upload the entire parent folder, GitHub says there's too many files to upload and tells me to reduce the number I'm uploading.
The crucial part is though, the folder has to be uploaded as a whole, as it itself is within a GitHub repository with other files with different folders in.
That means when I go onto my repository, I need this folder's files to display within the folder, and not separately within the repository. I need all of the files to be within this folder, within the parent repository, excluding the node_modules folder.
For example ->
Parent repository -> Child Directory (what I'm uploading) -> Individual files
I've tried to add the node_modules folder to my gitignore through the following methods:
Adding: node_modules/ to my gitignore file
Writing: echo node_modules >> .gitignore through my terminal
Adding a separate gitignore file within my node_modules file with a * in it
None of them have worked and I can't find any other solutions. For reference I'm using a Mac.
Does anyone have any idea what I'm doing wrong, or how it'd be best to do it?
By default, you do not need to include the node_modules folder in your repositories because the package.json file contains all of your project's dependency information. This means that anyone who clones your repository can run npm install and have the entire node_modules folder without problems.
To solve this you can create your own .gitignore file, creating a new file at the root of your project and renaming it to .gitignore (writing exactly that way). Then you can open it with any text editor and add */node_modules to one of the lines.
This will likely solve your problem.

Cleaning up and Migrating existing Unity project into new one or another PC

I wish to copy my existing Unity project into a new blank Unity project. It appears all the object references and many scripts are not configured properly/present in the Hierarchy in my scenes.
I only copied my assets folder/package.json into the new Unity project, because the rest of the files are dirty and have cached a lot of useless information.
Where are the files, detailing the scenes data located? I want to copy that over so I can run my scenes with all the object references, and scripts set onto the correct game objects.
Before starting always make Backups - you never know!
Cleaning Up / Migrating as a project folder
In general you will always need the Assets, ProjectSettings and the Packages folders (state Unity 2019 - relevant folders/files might change between versions)
All the rest you can delete and Unity will recreate/recompile them when you open the project again.
Also see Behind the Scenes (for newer Unity versions refer to Using external Version Control instead)
When backing up a project, or adding a project to a Version Control Repository, you should include the main Unity project folder, containing both the Assets
and ProjectSettings and Packages folders. All the information in these folders is crucial to the way Unity works.
As the names say
Assets are all your assets like scripts, images, prefabs etc. including alse the scenes.
ProjectSettings are all general settings for your project regarding things like quality, physics, player strings etc
Packages defines which packages shall be automatically imported by the PackageManager (manifest.json), which ones are dependencies, and which are even local packages (if any)
For me also some of the Library/*.asset files make sense to keep .. they store e.g. the build settings, target platform etc. so I don't have to configure them / switch platform from scratch every time I "reset". It's up to you of course if you want to do this as well.
You can also use any other version control system ... or of course also remove according folders and files manually but I always use GIT for my projects.
Also refer to Using external version control systems with Unity for some general information about the setup for version controlling your project(s).
So when I want to clean up a repository before coping it I usually use the following as *.gitignore (it is very basic - for a more complete and constantly updated version see the one on Github !).
Everything listed here can basically be deleted and will be re-compiled the next time you open the project in Unity. (Lines starting with ! are exceptions I added because as said for me it made sense to keep those as well.)
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/
# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/
# Recordings can get excessive in size
/[Rr]ecordings/
# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*
# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*
# Visual Studio cache directory
.vs/
# Gradle cache directory
.gradle/
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db
# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta
# Unity3D generated file on crash reports
sysinfo.txt
# Builds
*.apk
*.aab
*.unitypackage
*.app
# Crashlytics generated file
crashlytics-build.properties
# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
and as said for me personally it sometimes makes sense to add
# keep the *.asset files from Library
!/[Ll]ibrary/*.asset
If not done yet first initialize the repository running
cd your/project/root/path
git init
git add .gitignore *
this will show some warnings for every file that is listed in the .gitignore but you can ignore those warnings. It only says something similar like
You are trying to add an ignored file to the commit and it will be skipped
than run
git commit -m "Initial commit"
to make your first commit.
Now finally you can simply run git clean
git clean -xfd
which removes every file that is not tracked (so be sure to have always all files you want to keep at least staged (git add) or better commited first) or would be ignored by the *.gitignore.
-f
If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f, -n or -i. Git will refuse to delete directories with .git sub directory or file unless a second -f is given.
-d
Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. Use -f option twice if you really want to remove such a directory.
-x
Don’t use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with -e options. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build.
If unsure you can also add a
-n
Don’t actually remove anything, just show what would be done.
Note If you already had a .git repository but added / edited the .gitignore afterwards also refer to How to make Git "forget" about a file that was tracked but is now in .gitignore?
Migrating using UnityPackage
Another option for moving scenes or parts of the Assets between two different projects is using a UnityPackage. Note that this will not include any installed packages, settings etc but purely the assets and their asset-dependencies (linked prefab, materials, textures etc)!
From your current project export a UnityPackage
Excerpts from the Docs:
Use Export Package to create your own Custom Package.
Open the Project you want to export Assets from.
Choose Assets → Export Package from the menu to bring up the Exporting Package dialog box. (See Exporting Package dialog box image
below.)
In the dialog box, select the Assets you want to include in the package by clicking on the boxes so they are checked.
Leave the include dependencies box checked to auto-select any Assets used by the ones you have selected.
Click on Export to bring up the file explorer, and choose where you want to store your package file.
Name and save the package anywhere you like.
HINT: When exporting a package Unity can export all dependencies as
well. So, for example, if you select a Scene and export a package with
all dependencies, then Unity exports all Models, Textures and other
Assets that appear in the Scene as well. This can be a quick way of
exporting several Assets without manually locating them all.
alternatviely to step 2 you can also Right-Click on the Assets folder in the Project View and find the Export Package option in the context menu.
and then in the new project Import the UnityPackage
To import an Asset package:
Open the Project you want to import Assets into.
Choose Assets → Import Package → Custom Package.
In the file explorer, select the package you want and the Import Unity Package dialog box appears, with all the items in the package pre-checked, ready to install. (See Import Unity Package dialog box image below.)
Select Import and Unity puts the contents of the package into the Assets folder, which you can access from your Project view.
Alternatively to step 2 and 4 you can even simply drag and drop the unitypackage file into the Assets folder via the Unity Editor.
I wanted to do something similar which would apply to the "Move to Another PC" part.
I noticed that my projects are taking quite the amount of space and wanted to clean the proyect. I followed derHugo answer recommended "git clean" procedure but using his linked GitHub .gitignore file.
I had to make some changes so it work's on Unity 19.4:
# This .gitignore file should be placed at the root of your Unity project directory
#
# Modified from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
# Keep Library Folder
#/[Ll]ibrary/
/[Ll]ibrary/Artifacts/
/[Ll]ibrary/ArtifactDB*
/[Ll]ibrary/PackageCache/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/
# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/
# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta
# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*
# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*
# Visual Studio cache directory
.vs/
# Gradle cache directory
.gradle/
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db
# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta
# Unity3D generated file on crash reports
sysinfo.txt
# Builds
*.apk
*.aab
*.unitypackage
# Crashlytics generated file
crashlytics-build.properties
# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
Basically what I did was to not ignore the entire Library folder and only ignore the following:
/[Ll]ibrary/Artifacts/
/[Ll]ibrary/ArtifactDB*
/[Ll]ibrary/PackageCache/
Here's the procedure you should follow:
Backup your Project just in case.
Put the supplied .gitignore file on your project's root directory
Run the following commands:
# Initialize Repository
git init
# Add .gitignore file
git add .gitignore
# Add the rest of the files
git add *
# Commit changes
git commit -m "Initial Commit"
# Clean all untracked files and folders
git clean -Xfd
*Notice the -X option is capitalized on the git clean command, this avoids erasing any folder that's empty and untracked.
To verify everything is fine:
Load your Unity Project and check everything is still working correctly
Run git clean -Xfd once more to clean the project's files that were rebuilt by Unity.
Again, thanks derHugo for his detailed answer which was used to make this work on latest Unity releases.

ignoring the build folder in an eclipse project in git repo

I am using eclipse java as an editor and would like to use the .gitignore to exclude the build folder for the project. This is what I have currently written in my .gitignore. The syntax seems to be right; I used the git documentation but I may have interpreted it wrong.
#ignoring the files within the build folder
/build/
build/**
I'm using a brand new repo so I shouldn't have any problems with already logged files in the repo.
I am trying to get git to ignore the build folder in the project file using a .gitignore. The ignore file didn't work. What could be a solution?
The way the .gitignore is written, this file needs to be in the same subfolder as the build folder, the file being ignored.

There is no "zip download" button to download source in .zip on github

I want to download this source file in the zip here:
https://github.com/xdtianyu/android-4.2_r1/tree/master/packages/apps/SoundRecorder
But there is no Zip Download button. There is a Zip Download button in the root directory of the repository:
https://github.com/xdtianyu/android-4.2_r1
But I don't want to download the whole repository. How can I download that single project (specific subdirectory)?
I read this topic but still, I can't Download source as the zip file:
Download single files from GitHub
How to download source in ZIP format from GitHub?
You can't download a subdirectory from GitHub as a zip file.
Some options are to
download the full zip and manually extract the subdirectory that you want, or
use git with sparse checkouts instead of downloading as a zip file.
This approach does download the entire repository into the .git directory, but your working copy will only contain the files and directories that you want.
For more information on sparse checkouts have a look at this answer.
Use DownGit; you can download individual files or directories, and even create download-link for them-
You can also configure properties of the download-file. See here for detailed usage.
Disclaimer: I fell into the same problem as the question-asker, could not find any proper solution, so I created this tool for my own use, and later made it available for everyone.