IntelliJ IDEA shows freshly checked-out files from GIT as changed while there is no difference - intellij-idea

Like in the title, after checking out repository from GIT, the files are shown as changed (blue) by IntelliJ IDEA.
But they are not.
How to fix that?

What causes the problem is probably one of those:
line-ends converted / or not to CRLF (on the fly)
changed file mode
ignored / or not case
Here is why that may happen:
IntelliJ IDEA is using a different Git than the one that was used to check-out the files
Check which Git is in the System Path and which is in Settings > Version Control > Git > Path to Git excutable.
git --version may be useful too to check versions in different contexts
Even if versions are the same, what makes the difference is the configuration
git config --list shows what parameters were set
In my case, the Git version was the same, but from two different paths (one came in the package, one was installed independently). The configuration was different (default vs adopted) and that was enough to make everything quite confusing.
Especially check:
core.autocrlf=true (mainly on Windows)
core.filemode=true
core.ignorecase=true

Related

Create repository in non-empty remote folder

It's been 14 years since I last worked with svn and appearently I have forgotten everything...
I have an existing web-project, consisting of a bunch of php, html, js and other files in a directory tree on a V-Server. Now I want to take these folders under version control and create a copy on my local machine using svn. So I installed subversion according to these instructions: https://www.linuxcloudvps.com/blog/how-to-install-svn-server-on-debian-9/
Using the already-present apache2.
But now I kinda hit a roadblock. If I try svnadmin create on the existing folder, it tells me that is is not empty and does nothing really. All the questions and answers I find here and elsewhere are either
a) focussing on an already existing folder on the local machine
b) assuming more prior knowledge than I have right now aka I don't understand them.
Is there a step-by-step guide for dummies anywhere on how to do this? Or can anyone tell me in laymans terms how to do this?
I can't believe this case never comes up or that it is really very complicated.
At the risk of failing to understand your exact needs, I think you can proceed as follows. I'll use this terms:
Code: it's the unversioned directory at V-Server where you currently have the bunch of php, html, js and other files
Repository: it's the first "special" directory you need to create in order to store your Subversion history and potentially share it with others. There must be one and there can only be one.
Working copy: it's the second "special" directory you need to create in order to work with your php, html, js... files once they are versioned and it'll be linked to a given path and revision of your repository. At a given time there can be zero, one or many of them.
Your code can become a working copy or not, that's up to you, but it can never become a repository:
$ svnadmin create /path/to/code
svnadmin: E200011: Repository creation failed
svnadmin: E200011: Could not create top-level directory
svnadmin: E200011: '/path/to/code' exists and is non-empty
Your repository requires an empty folder but it can be located anywhere you like, as long as you have access to it from the machine you're going to use in your daily work. Access means it's located in your PC (thus you use the file: protocol) or it's reachable through a server you've installed and configured (svn:, http: or https:).
$ svnadmin create /path/to/repo
$ 😎
Your working copies can be created wherever you need to work with your IDE. It can be an empty directory (the usual scenario) or a non-empty one. The checkout command retrieves your files from the repo and puts them in the working copy so, at a later stage, you're able to run a commit command to submit your new and changed files to the repository. As you can figure out it isn't a good idea to create a working copy in random directories because incoming files will mix with existing files. There's however a special situation when it can make sense: when the repository location is new and is still empty. In that case you can choose between two approaches:
If you want code to become a working copy, you can check out right into in and then make an initial commit to upload all files:
$ svn checkout file://path/to/repo /path/to/code
Checked out revision 0.
$ svn add /path/to/code --force
A code/index.php
$ svn commit /path/to/code -m "Import existing codebase"
$ Adding /path/to/code/index.php
$ Transmitting file data .done
$ Committing transaction...
$ Committed revision 1.
If you don't care about code once it's stored in the repository or you want your working copy elsewhere, you can import your files from code and create a working copy in a fresh directory:
$ svn import /path/to/code file://path/to/repo -m "Import existing codebase"
Adding code/index.php
Committing transaction...
Committed revision 1.
$ svn checkout file://path/to/repo fresh
A fresh/index.php
Checked out revision 1.

How can I clone a CodenameOne IntelliJ project and continue working on it?

I'm using a .gitignore file that was recommended for use with CodenameOne projects (See the blog post) and have committed my project to GitHub. Now I want to retrieve that project to a new PC and continue working on it but I'm having endless troubles doing it.
Shai shared a "quick trick" workaround which involves creating a new project then copying the relevant files from a clone of the Git into it, but then it's not a proper clone of the github repo that can be worked on and then synced back up to the remote.
So what I'm asking is: what steps (and troubleshooting resouces) would I use to ensure that:
I am storing the right files to the GitHub Repo to enable success
The IntelliJ Project will work with the retrieved files
I can commit changes back to the Repo going forwards.
Sorry, I'm a bit new to juggling GitHub repos and CN1's plugin structure for Idea has me mystified (I tried merging a new project with a directory which has a clone of the GitHub repo and the CN1 plugin is disabled - can't click on it)
I resorted to using the following .gitignore (using Codepoint One with IntelliJ IDEA):
# macOS
.DS_Store
# build artifacts
/build/
/dist/
/lib/impl/
/native/internal_tmp/
/out/
# idea
/.idea/**/workspace.xml
/.idea/**/tasks.xml
*.iws
With this setting, most of the IntelliJ configs are committed, as well as some binaries: CodeNameOneBuildClient.jar, JavaSE.jar, lib/CLDC11.jar, lib/CodenameOne.jar, lib/CodenameOne_SRC.zip.
This is not optimal (the binaries don't really belong in Git and take about 40 MB combined). But this way I can clone the project on a different machine and start working right away. It also doesn't produce Git diffs on every build — but only if the libs are updated.
IntelliJ/IDEA Codename One projects are nearly identical to NetBeans Codename One project with the one major difference being the additional idea directory. Just copy that directory from a working intelliJ project and add it to the gitignore. The project should work.

IntelliJ: How to create a local Java project copy for backup?

I'm new to JavaFX 8 and the IntelliJ IDE. I have a JavaFX8 project that works but not as I would like. I'd like to try another approach but the substantial changes may not work. I don't want to loose code I have working.
To save code I have working, I've been creating a new project and then locally copying all the folders(.idea, out, src) and files except .iml, of the working project into the appropriate folders in the new project with the newly generated .iml.
This always seems to work but is it proper procedure?
I'm not on a team of developers and have yet to learn Git/GitHub.
Please advise. Thanks.
Maybe you should learn how to use a Version Control System like Git, then you can create a project repository and have different branches for things you want to try out. Keeping the working code in your master branch will prevent you loosing your working code. Also, when using a vcs you can always revert to versions of your code that have been working. The IntelliJ Idea IDE has perfect support for working with all different types of version control systems. If you don't want to learn any forms of vcs then there is no other way to "backup" your working code.
Is it proper procedure? It's probably not how most people would go about achieving what you want to achieve but it's certainly workable. If you wanted to stick with that for simplicity now, I'd copy the whole directory structure, delete the .idea and .iml files, and then create a new project in IntelliJ on that clean copy: IntelliJ will automatically set up folder structure based on the existing source without you having to go through any additional manual setup.
If you're willing to experiment with the git route, to achieve the basics of what you want to achieve is not very complicated and I've written a small quick-start below. IntelliJ offers very good support for Git, and once your repository is created you can do everything you need from the IDE. I'm going to assume you're working on Windows, although the steps shouldn't be too far removed on other platforms.
Install Git
You can download and install Git from https://git-scm.com/download/win, which will install a command shell called Git Bash.
One-off setup for your project
Open up git bash and go into the directory containing your source. Rather than seeing separate drives as Windows does, Git Bash assumes there is a logical 'root' directory under which all your files are accessible. Your C: drive will be /c. To move around you can use cd to change directory (using / instead of ) and ls to list files instead of using dir.
Assuming your source code is in C:\projects\myproject:
cd /c/projects/myproject
git init
The second line above creates a git repository in that directory. This doesn't affect your code, it just creates a folder called .git that contains all of the book-keeping information.
You don't want to have every file under version control - in particular you don't want your build outputs. You need to set up a file in your project directory called .gitignore which tells git which files and directories should be ignored. As a starting point you can copy https://github.com/github/gitignore/blob/master/Java.gitignore and rename the file to .gitignore
Basic Commands and committing your initial version
There are a small number of basic commands:
git status
Running git status will tell you which files have been modified, which are not under version control, and which files have been added to the staging area to be committed next time.
git add path/to/file
This adds a file to the staging area waiting to be committed. You can add multiple files to the staging area before committing them in one go.
git commit -m "description of your change"
This commits all of the staged files as a new version, which the specified commit message.
If you go into your project directory, do a git status and check through the list to make sure there's nothing you don't want to have under version control, then you can do git add . to add everything to the staging area and git commit -m "Check in initial version of the source code" to commit it to the repository.
After you've committed, you can run
git log
To see a history of all of the changes. IntelliJ has a view that will show you the same thing.
Creating an experimental branch
This is where git shines; if you want to try something experimental you can create a branch of your project while allowing git to preserve the original version.
git checkout -b experiment1
Will create and switch to a branch called experiment1. You can delete, rename, move, rewrite and develop whatever you like on this branch. The changes you commit will be independent of your original working version.
You can switch back to your original version (preserving all of the changes you've committed on that branch) using:
git checkout master
Where master is just the name of the default branch created when you ran git init. The experimental version will still be there and can be switched to again using git checkout experiment1 or from IntelliJ using the branch selection in the bottom right corner of the status bar.
If you decide that the changes you've made in experiment1 are to become your new "good" version, you can merge them back into the master branch and repeat the cycle from there.

Can a git repository have N working trees

I try to write a file store based on libgit2.
Software snapshots should be saved as branches mysoftware and specific versions committed and tagged. Then later I want to checkout the tags to different directories.
When looking at git_checkout_tree, it seems like there is only one working tree for a repository and thus it does not even seem possible to checkout multiple working trees concurrently.
Is this correct!?
EDIT:
Additionally, I would like for this thing to work on Windows without the need for cygwin!
The git_checkout_opts structure in libgit2 contains a target_directory option that will allow git_checkout_tree() to write to a different directory instead of using the default working tree for the repository. This would allow you to custom build a solution with libgit2 that maintained multiple checked out copies.
Without using that option, a libgit2 git_repository object expects there will be just one working directory and looks to the core.worktree config option if it isn't the "natural" working directory for the repository.
The git-new-workdir tricks with symlinks in the .git directory don't work great with libgit2 right now, I'm afraid, and particularly doesn't work well on Windows. I'd love to see this addressed, but it isn't too high on my priority list.
Git doesn't support this natively, but you can use git-new-workdir to do it.

Intellij IDEA diff file compare (without VCS)

I heavily rely on git in my workflow. However, I do not use IDEA's integration since using the shell and aliases has always been faster. Now I noticed that when enabling the VCS-support, there is an Compare with same repository, Compare with branch, Compare with ....
Now I wonder if it is possible to merge a diff file (with all the <<<<<<<). Even when enabling the VCS-support, IDEA does not seem to support that.
Does anyone know if (and how) merging a diff file with IDEA is possible?
I'm not sure if that's what you ask. But it's possible to select two files in the project's file browser and compare them by clicking 'Compare Two Files' in the context menu. If you do so the diff/merge dialog will open with same possibilities as when opened with VCS related commands.
Why don't you just enable the IDEA git integration (to be able to do diffs in IDEA) and keep using the shell for the other git commands. I have worked that way with both Git and Perforce, and IDEA works fine that way.