Can IntelliJ IDEA select "the current branch and its remote tracking branch"? - intellij-idea

When working on a branch together with colleagues, I find it useful to limit IntelliJ IDEA's Git Log view to the local branch I'm working on plus the remote tracking branch. This way, I see all the commits that are relevant to working on this branch.
Every time I switch branches and want to get that filter, I manually select HEAD and the remote branch. I found no way to tell IDEA to always select the current branch and its remote tracking branch.
Is there a way to let the Git Log view select "the current branch's remote tracking branch" once, and have it automatically pick the right remote branch when I checkout another local branch?
I'm currently using IntelliJ IDEA 2019.3.4, but will likely update to 2020 soon.

You can update to 2020 and check new Branches Dashboard under Log tab in Git tool window.
Then you can select local and remote branches and you will get log filtered.
Please see what's new in 2020 here:
https://www.jetbrains.com/idea/whatsnew/#version-control
Also please see and vote:
https://youtrack.jetbrains.com/issue/IDEA-233730

Related

How do you create (or set) a tracking branch? LibGit2Sharp 0.26.2

I need to add a branch that tracks a remote using libGit2Sharp v0.26.2. Every example I've seen uses the seemingly deprecated repo.CreateBranch() API though I'm not certain that matters.
Branches are created in 0.26.2 by using repo.Branches.Add().
I've attempted the following but I'm clearly missing something (assumes "repo" has been created and initialized and instance repo is created):
repo.Network.Remotes.Add("origin", path_to_remote);
var trackingBranch = repo.Branches["origin/myBranch"];
repo.Branches.Add("myBranch", trackingBranch.Tip);
var branch = Commands.Checkout(repo, repo.Branches["myBranch"]);
repo.Branches.Update(branch, b => b.TrackedBranch = trackingBranch.CanonicalName);
Commands.Pull(...);
This code will alway fail as "origin/myBranch" does not exist in repo.Branches even though "myBranch" exists on the remote. More interestingly, if I use the git command like and (once the code adds the remote) and do a "git pull" things work fine.
FYI: This code is cobbled together from looking at numerous examples that use deprecated calls. I've been unable to locate anything using the current version. Hopefully someone out there has experience with the current version.
Thanks in advance.
myBranch might exist on the remote repository, but in the code you posted, you never actually "fetch" the branches from the remote repository. Just adding the remote is not sufficient (this just configures the remote repository, but does not actually retrieve any information from it) - you also need to fetch the latest branches from the remote repository. After you fetch, your local Git repository will know about the branches on the remote, and then you can create a local branch from it.

How to open specific branch of git repo in intelliJ

I am trying to see the files of particular branch of my repo. How can I open that file in intellij.
When I am trying to open repo in intellij it is showing code of master branch.
pls Help!!
One quick option here, which doesn't require actually checking out another branch, would be to right click the file of interest and then choose:
Git => Compare with branch...
This will bring up a dialog listing all branches for your current repository. You may choose the branch of interest. This in turn will launch a side-by-side window showing both the version from the current branch (presumably master) right next to the version from the branch you have chosen.
Going this route might actually be what you want, if your intention be to compare a given file in the current branch against a version in another branch.
Hi if you have multiple branches exp.- branch1, branch2,branch3
and you can open a particular branch file,
checkout particular branch & open file easily
CMD= git checkout branch1

How to make Gitlab CI automatically create pipelines on every commit

Back in the days I've seen on a demo (can't recall now where) where after every push, the Gitlab CI automatically created a pipeline for this commit in an appropriate branch, but without running it automatically.
This allowed user to run pipeline on any branch without having to manually select branch from "new pipeline" button.
Can't find such information in the documentation. Perhaps it was a hack but nonetheless it worked.

Get back lost shelf changes

I have shelved my 26 java files changes via Intellij Idea 2016.2.1 and I checkout to different branch.
When I came to old branch to check my shelved changes.
I gone a mad now, I lost all the files. I was worked nearly two months
Can somebody help to get it back?
You can restore the state of those files if they were edited in IntelliJ. Use local history to see all the changes made in IntelliJ (VCS -> Local History -> Show History).
Even there isn't Shelf tab in IDE you can find shelved changes as patch files at {ProjectName}/.idea/.idea.{ProjectName}/shelf/.idea/shelf.
Then your can apply any selected patch.
I was able to view lost changes and revert back to them by:
right click on project directory, select Local History > Show History
Find the entry in the history menu that you want to restore. You can examine the files by double clicking on the entry and the files to examine differences.
Right click on the entry you want to restore, and select Revert
Note in my case Git>VCS Operations>Show History showed nothing. Only through the Project Files menu.
Andrei's answer was helpful for my situation where I renamed my project and my previously shelved changes were no longer found under the shelf, but I did run into an issue when applying the patch file because I was prompted to "Select missing base" for various files in the patch. Similar to what is seen in the screenshot below:
https://youtrack.jetbrains.com/issue/IDEA-183910
I was able to avoid having to "Select missing base" for various files by first changing the default shelf location and then applying the patch.
https://www.jetbrains.com/help/idea/shelving-and-unshelving-changes.html#change-shelve-location
Also, I found my patch in this location:
{ProjectName}/.idea/shelf
instead of the aforementioned location:
{ProjectName}/.idea/.idea.{ProjectName}/shelf/.idea/shelf
Maybe this will help someone:
I lost part of my shelved changes in combination with an update of IntelliJ. I'm not sure if the update was the reason but eventually most of my most recent (and important) changes were gone.
I couldn't restore them from local history as this does not "survive" an update of IDEA. But in the files I saw that there still is some data:
C:\Users\myUser\AppData\Local\JetBrains\IntelliJIdea2021.2\LocalHistory had a changes.storageData with ~50MB.
Copying the files to the folder of the new version didn't help as the files got overwritten again.
Solution:
I was able to get the old version of IntelliJ (2021.2) here and installed it. This can be done in parallel, without removing the newer version.
Here I was able to retrieve my changes from the Local History and shelve or apply them again.
Hint: Backup the "Local History" folder (or the whole IntelliJIdea20xx.x folder) before you start. I don't remember if I had to copy it in there again or if it worked out of the box. (Just to be sure the local history doesn't get lost).
I've also experienced this bug repeatedly and hence no longer use shelved changes, but rather the Git CLI directly. As of 2022 Jetbrains IDE's still cannot be trusted with their "Smart Checkout" feature, which has a small probability of the total loss of your files (experienced personally in both IntelliJ & Rider).
Unlike another comment here regarding using the Local History, this did not work for me as the history showed nothing. I've also lost many hours of work due to this bug which remains unfixed.
The solution is to use "git stash -u" on the command line, then checkout the desired commit. Once youre done, type "git stash apply" to restore your files. Trusting the "smart checkout" feature is like playing Russian roullette. It's IDE magic that may just fail and you lose everything.

Can git cherry-pick be done in accurev?

I'm looking to do something similiar in functionality as git cherry-pick. My situation is thus: I mistakenly promoted from from stream C to Stream B, realized it was an error and reverted the transaction, this succeeded. But unfortunately I now no longer have the code In stream C that I had before the promote. I've tried doing a send to workspace and merged the underlaps but this puts me in the same place I was in before, I no longer have my changes. if I keep the overlaps I get overlaps with almost all the files.
I'm really at wits end, I know if this was Git I would have reverted my bad commit, merged the reversion into my feature branch, then cherry-picked the original commit.
accurev has broken me, I'm ready to cry and need some help :,(
In the future, you could have done a demote (new feature in AccuRev 6.2.0) of your changes in streamB and put them back in streamC (very slick new feature IMO).
To resolve your situation, perform the following steps.
Hang a workspace off of streamC.
Update this workspace.
Right click on streamB -> Show History -> Select the promote transaction -> Right click -> Send to Workspace -> Choose workspace from step 1.
Depending on your version of AccuRev, click on the "Default Group" filter or "Outgoing" filter.
Select all of the files included from the send to operation -> Right click -> Merge. You will not want to automatically keep the merge, but need to manually select the version of the file in your workspace (lower right hand pane). This contains the changes from your initial promote. After you have done this, keep and exit.
Now promote your changes into streamC.
The demote feature basically does all these steps for you in one operation BTW.