What is a changelist in IntelliJ IDEA? A list of changes compared to what? What does it mean that I can have multiple changelists?
Especially, when I revert back to an earlier version (using VCS) IntelliJ wants to create a new changelist for that. Why? In that case the changes will be related to what? Let's say I revert to version 9 from version 23. Then the changeslist will contain the changes between version 23 and 9 or between 8 and 9?
I tried to read the documentation but it did not give me any enlightment at all.
Is the IntelliJ changelist the same as, for example, the concept of changeset in Mercurial, in which case the changelist is just an other name for a node in the revision history graph, conceptually?
A changelist is a set of files you have changed as compared to the version control history. It differs from a version control changeset in that a version control changeset is created when you commit the code. An IDEA changelist is present while you are editing the code, and then is cleared when you commit the code.
IDEA changelists allow you to track the changes you are making. You can quickly view all the files that have changes (as compared to the last version control update/pull). They are very helpful in that you have have multiple changesets created at a time (but only one active), and they can be linked to tasks (i.e. tickets or bug trackers).
So lets say I'm working on "new search feature". I create a changelist for that and make it active. As I code, all my changes go on to that list. As I am working, I get an emergency bug fix for a DB Hang. I create a "DB Hang" changelist and make it active. Now any changes/edits I make go on the "DB Hangs" changelist. When I am completed, I can commit only files on the "DB Hangs" changelist. This prevents any of the files I changed while working on the (still incomplete) "new search feature" task. Once the "DB Hangs" code fix is committed, I make the "new search feature" changelist active and (most likely) delete the "DB Hangs" changelist and continue on with the coding of the new search feature. I personally also have a "Do Not Commit" changelist where I put any changed files I do not want to commit to version control (for example changes to a config file for isolated/local testing). Note: you can easily move changed files from one changelist to another.
UPDATE
As of version 2018.1, IntelliJ IDEA allows a file to appear on multiple changelists. From the blog announcing the new feature: "the IDE now provides the ability to associate the code chunks, not the whole file, with a changelist, and track them separately. Code chunks can be quickly moved between changelists using the Move to another changelist action which is available from the context menu of the Diff pane in the Commit Changes dialog." See that blog for more detail and information.
For versions prior to 2018.1:
When you have multiple changelists -- such as the above bug example -- if you try to modify a file on the active changelist that is also on an inactive changelist, IDEA warns you and the file name turns red. For example, lets say that as part of my initial work for the "new search feature" I made a change to "User.java" that is dependent on a number of new files I created for the "new search feature" work. I then get the emergency bug and make and switch to the "DB Hangs" changelist. As I am fixing that bug, I realize I need to make a change to User.java. When I start editing the file IDEA warns me it is part of another changeset. This prevents me from later on committing User.java without the new code it depends on and thus breaking the build. When I get that warning I have to make a decision on how to handle it. I could shelf the "new search feature" changelist before editing User.java for the "DB hangs" fix, and then unshelve it afterwards. (This is typically the best thing to do when a lot of files are needed in both fixes.) Alternatively, I could move the file to the "Db Hangs" changelist. Then if I determine the changes are OK to go in with the bug fix (i.e. has no other dependencies) I can just commit together. Or I can rollback the changes in that file. (And then use local history later to get them back). Or I could comment out the changes. Etc.
(END OF UPDATE)
To answer this question:
Especially, when I revert back to an earlier version (using VCS) IntelliJ wants to create a new changelist for that. Why? In that case the changes will be related to what? Let's say I revert to version 9 from version 23. Then the changeslist will contain the changes between version 23 and 9 or between 8 and 9
When switching to a different VCS version, IDEA will only want to create a new changelist if you have made code changes to the version that was previously active. The reason for that is the code changes you made are "changes to version 23 of this file". When you revert to version 9, those changes are no longer valid per se. It assumes you want to track the changes you make to version 9 separately. I've never run into this situation (based on my personal workflow for working with older versions or branches). But if you wanted to use the changes you made while viewing version 23 with version 9, you should be able to move then over to the new changelist, or make the original change list active.