I have a GitHub repo with some python code and some text files. However, I want to add some Golang code to my project.
So basically my issue is that I'm confused on where to set my GOPATH so I can work with Go source files in the same place that I work on python files. Do I set my GOPATH to my repo path, then setup the \src\github.com\user\ directory and put my Go code there? Do I put Grandzam where user is, or leave it alone because someone else is working with me on the repo?
https://golang.org/doc/install Test your installation is what I am confused about.
I would recommend setting up an environment consistent with the recommendations in the "Organizing your code" section of the language documentation.
First, choose a top level directory (I tend to use ~/devel), and set the value of your GOPATH environment var to that location, and add the GOPATH/bin dir to your path. Put it in your the appropriate session startup file (~/.bash_profile or similar). In my case, I would put these lines in that file:
export GOPATH=$HOME/devel
export PATH=$GOPATH/bin:$PATH
Quoting from the documentation:
To give you an idea of how a workspace looks in practice, here's an example:
bin/
hello # command executable
outyet # command executable
pkg/
linux_amd64/
github.com/golang/example/
stringutil.a # package object
src/
github.com/golang/example/
.git/ # Git repository metadata
hello/
hello.go # command source
outyet/
main.go # command source
main_test.go # test source
stringutil/
reverse.go # package source
reverse_test.go # test source
golang.org/x/image/
.git/ # Git repository metadata
bmp/
reader.go # package source
writer.go # package source
... (many more repositories and packages omitted) ...
Next, clone your git repo into the appropriate path under the $GOPATH/src tree. In my case it would be $GOPATH/src/github.com/user/repo.
Now you should be all set to work on both go and python code without much trouble.
Related
so I have updated my version of IntelliJ and Jetbrains decided to create new files and folders on my code folder. (see screenshot below)
I don't really want Jetbrains/IntelliJ clogging up my repo so I decided to add this entry on the .gitignore on the parent folder (e.g. /Users/myuser/Documents/myrepo/.gitignore)
##########################
## Jetbrains/IntelliJ
##
.idea/
.idea_modules/
*.iml
My problem with Gitkraken is that it continues to show all files and folder (as unstaged) inside "/Users/myuser/Documents/myrepo/.idea" even after I restart the app. I'm not sure if this matters but I am using the Gitkraken macOS version.
Some things to try:
Commit your .gitignore first. (Just a guess)
There is an option in GitKraken to ignore files individually, Right-Click (on the unstaged file) -> Ignore. This will add it to .gitignore.
The best way is to use a global ignore file like what is demonstrated here
GitKraken reads the global ignore file as well as the ignore files in the repo.
It does require a little bit of command line use but not much.
create a file in your home directory touch ~/.global_gitignore
add things like the .idea and other things in that file you never want in any repos (including OS specific things) see https://github.com/github/gitignore for many helpfil things to add
run the following command git config --global core.excludesfile ~/.global_gitignore
Enjoy never needing to exclude them from your repos again.
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.
Using GitHub's web-based interface I cannot figure out how to specify an alternate path / filename for the project's README file.
When creating a new README, the web interface does give me the option of using any arbitrary path or filename I want, but the file I select is not used as the project-level README. I would like it to be displayed when users visit the project page.
In the context of projects that are modules or extensions (e.g. Magento 1 modules) having all such README files at /README.md for all such projects would make them all get over-written in the final merge, so an alternate path or filename should be used (e.g. /docs/projectname/README.md or /projectname.md).
How can I do this in a way that specifies that file as the default README?
GitHub looks for README files in a few places:
If you put your README file in your repository's root, docs, or hidden .github directory, GitHub will recognize and automatically surface your README to repository visitors.
If you want to use another file for your project-level README I suggest creating a hidden .github/ directory and symlinking your file there with a name GitHub expects.
On Linux or macOS this should be fairly straightforward:
# From your repository root
mkdir .github
cd .github
ln -s ../docs/projectname/some-README.md README.md
On Windows things are a bit trickier.
Symbolic links are only available on NTFS filesystems on Windows Vista or later, and creating them requires special rights or Developer Mode. They are not supported by Git on Windows out of the box.
In your Git shell, in the root directory of your repository, enable symlinks for the current repo:
git config core.symlinks true
Now run cmd.exe as administrator¹ and cd to the repository root. Make your symlink:
mkdir .github
cd .github
mklink README.md ..\docs\projectname\some-README.md
Note that the name of the link goes before the name of the real file here, in contrast with the Linux and macOS instructions above. You can close cmd.exe now and go back to Git Bash.
Now commit .github/README.md and push to GitHub. You'll probably want to make sure that there isn't a real README file in any of the other locations GitHub uses (the repository root or a docs/ folder in the repository root).
Windows users who clone the repository won't get a symlink automatically. If they wish to have that behaviour they should clone with a special argument:
git clone -c core.symlinks=true <repo-url>
¹It's possible to grant mklink permissions to non-admin users, but running as administrator is likely the simplest solution.
I'm getting used to Go, and trying to understand how it works.
So I'm trying to run the test code from my repository zoonoo/go-ethereum, forked from the original repository ethereum/go-ethereum.
When I run go test . under the eth directory, I get the following error :
eth/api.go:37:2: use of internal package not allowed
37th line of eth/api.go is as follows : "github.com/ethereum/go-ethereum/internal/ethapi"
Does this mean when you fork a go repository, you have to change the path of all dependencies within the code to run the code?
Does Go package system support repository fork at all?
As illustrated in another Go project:
Cloning a fork
If you wish to work with fork of InfluxDB, your own fork for example, you must still follow the directory structure above. But instead of cloning the main repo, instead clone your fork. Follow the steps below to work with a fork:
export GOPATH=$HOME/gocodez
mkdir -p $GOPATH/src/github.com/influxdb
cd $GOPATH/src/github.com/influxdb
git clone git#github.com:<username>/influxdb
Retaining the directory structure $GOPATH/src/github.com/influxdb is necessary so that Go imports work correctly.
Replace InfluxDB name/URL by your project, and the same idea applies.
In your case, the GitHub fork is only there for you to push your contribution back to it, and to make Pull request from it.
It won't serve as a source for go get to work, since the packages wouldn't match your GitHub for repo URL.
This is because internal packages in go can only be imported by packages in the same directory root. It's kind of like package private classes in java. If you want to edit the code without having to rename all package imports you need to maintain the same folder structure that the package expects so if github.com/zoonoo/go-ethereum is in your $GOPATH rename the directory to github.com/ethereum/go-ethereum or create a symbolic link and work from the linked directory instead.
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.