FileMerge quits immediately after launching from SourceTree - xcode

I regularly use Atlassian SourceTree (on Mac OS X) to launch FileMerge to resolve git merge conflicts. Out of the blue it has stopped working: when I right click and select Resolve Conflicts > Launch External Merge Tool, FileMerge launches, creates its intermediate files, then immediately exits. SourceTree interprets that as the merge process being complete.
What's the issue and how can I debug/fix it?
I note that a previous question 'SourceTree filemerge quits immediately and creates 4 files. How to fix it?' does not address this particular scenario (for one, it says FileMerge quits in the title, but in the body it says FileMerge displays /dev/null as one of the panels. Additionally, my merge conflict is not due to a removed file.)

To diagnose the problem, I ran opendiff from the Terminal. I received the following error:
xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
To solve:
Open Xcode > Preferences > Locations
Click on the drop-down box beside Command Line Tools and select your current Xcode version. (This was empty for me because I had recently installed Xcode on a new Mac.)
Run opendiff in Terminal again, and the above error should no longer appear.
Now FileMerge will open correctly from SourceTree when you click Launch External Merge Tool.

For me, SourceTree didn't even launch FileMerge. When clicking Launch External Merge Tool nothing happened.
Moreover, running opendiff in Terminal worked as expected:
$ opendiff
opendiff[64176:5561154] too few arguments
opendiff[64176:5561154] usage: opendiff file1 file2 [-ancestor ancestorFile] [-merge mergeFile]
What helped me was manually configuring SourceTree to use FileMerge via the opendiff command with the following arguments: $LOCAL $REMOTE -ancestor $BASE -merge $MERGED
This way, SourceTree opens FileMerge as expected.

This helped:
https://gist.github.com/kylefox/4512777
Tell system when Xcode utilities live:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Set "opendiff" as the default mergetool globally:
git config --global merge.tool opendiff

If Xcode has recently updated itself, you may need to agree to the new license terms. If you have not agreed to the license terms, FileMerge (when launched from SourceTree) will quit immediately.
To check for this, open a shell and run as your usual user:
$ opendiff
If the license is the problem, it will tell you. To agree to the new license terms, you'll need to run open diff using sudo:
$ sudo opendiff
After agreeing to the license terms, you can now retry launching FileMerge from SourceTree using Resolve Conflicts > Launch External Merge Tool. FileMerge should launch and behave normally.

This also works to resolve the message "xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance":
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

I have encountered this problem and solved it with the answer here
So this time, when I had it again, I thought the same issue happened...
And after trying for almost an hour, I've realized that the Diffmerge (or any external diff tool) did not open because there was no file in the current branch to merge.
This can happen when you do Cherry Pick where the commits can be jumpy. Added this answer to remind people who are going to have the same issue.

Tick Allow Sourcetree to modify your global... solves the issue for me

Related

How to use git commands in Visual Studio 2019 Integrated Terminal [duplicate]

Visual Studio Code reports "It look like git is not installed on your system." when I try to switch to the git view. I know I have git installed and used by other Git clients. I guess if I reinstall Git following Visual Studio Code's instruction ("install it with Chocolatey or download it from git-scm.com"), it probably can fix the problem, but I don't want to mess up the existing Git clients on my system. Is there a reliable way to configure Visual Studio Code so it can find existing git installation?
Now you can configure Visual Studio Code (version 0.10.2, check for older versions) to use an existing Git installation.
Just add the path to the Git executable in your Visual Studio Code settings (menu File → Preferences → Settings) like this:
{
// Is Git enabled
"git.enabled": true,
// Path to the Git executable
"git.path": "C:\\path\\to\\git.exe"
// Other settings
}
Update 2020 (Mac)
I went through this $h!† again after updating to macOS v10.15 (Catalina), which requires an Xcode update.
And to clarify, while this post is about Visual Studio Code, this issue, is system wide. Your Git install is affected/hosed. You can try to run git in your terminal, Bash, Z shell (zsh), or whatever. It is now and it just won't.
It is the same fix. Just update Xcode. Start it up and agree to the license. That's it.
I hit this on Mac/OS X.
Symptoms:
You've been using Visual Studio Code for some time and have don’t have any issues with Git
You install Xcode (for whatever reason - OS update, etc.)
After installing Xcode, Visual Studio Code suddenly "can't find Git and asks you to either install or set the Path in settings"
Quick fix:
Run Xcode (for the first time, after installing) and agree to license. That's it.
How I stumbled upon this "fix":
After going through numerous tips about checking git, e.g., which git and git --version, the latter actually offered clues with this Terminal message:
Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.
As to why Xcode would even wrap it's hands on git, WAT.
Visual Studio Code simply looks in your PATH for git. Many UI clients ship with a "Portable Git" for simplicity, and do not add git to the path.
If you add your existing git client to your PATH (so that it can find git.exe), Visual Studio Code should enable Git source control management.
This can happen after upgrading macOS. Try running Git from a terminal and see if the error message begins with:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) ...
If so, the fix is to run:
xcode-select --install
from the terminal. See this answer for more details.
I had this problem after upgrading to macOS v10.15 (Catalina).
The issue is resolved as follows:
1.
Find the Git location from the terminal:
which git
2.
Add the location of Git in settings file with your location:
settings.json
"git.path": "/usr/local/bin/git",
Depending on your platform, the user settings file (settings.json) is located here:
Windows %APPDATA%\Code\User\settings.json
macOS $HOME/Library/Application Support/Code/User/settings.json
Linux $HOME/.config/Code/User/settings.json
In Visual Studio Code, open 'User Settings': Ctrl + P and type >sett. Press Enter.
This will open the default settings on the left side and User Settings on the right side.
Just add the path to git.exe in user settings:
"git.path": "C:\\Users\\[WINDOWS_USER]\\AppData\\Local\\Programs\\Git\\bin\\git.exe"
Replace [WINDOWS_USER] with your user name.
Restart Visual Studio Code.
First check if Git* is installed or not in your system by typing the command in cmd /command prompt (in Windows):
where git
If you get an output like this,
λ where git
C:\cmder\vendor\git-for-windows\cmd\git.exe
Then Go to Settings → Preferences → Settings and put the bellow code** right part.
{
// If git enabled?
"git.enabled": true,
// Path to the Git executable
"git.path": "C:\\cmder\\vendor\\git-for-windows\\cmd\\git.exe"
}
If you don't have Git installed, install Git from https://git-scm.com/
** Just add a double slash (\\), just like the above code.
UPGRADE TO MacOS Ventura < 13.0
As of November 2022
Upgrading to MacOS Ventura does not seem to affect your coding environments too much.
After upgrading to macOS Ventura your Terminal and VScode will give off a few errors. Such as:
It look like git is not installed on your system ..
or
can't find Git and asks you to either install or set the Path in settings
some errors depend on your zsh setup or other customizations.
These common problems can be resolved by simply by reinstalling xcode command line tools and updating Homebrew - since your terminal might be affected reinstall from apples executable https://developer.apple.com/download/all/
developer.apple.com you will need to log in with your apple id.
Once installed, update Homebrew
brew upgrade
Mac M1 - M2 machines likely have some native and ARM applications so run:
arch -arm64 brew upgrade
Close all terminals and Vscode to restart!
reopen Vscode, errors should be gone.
If Vscode is still looking for Git path you will need to add it manually.
Find git location and copy from the terminal:
which git
and add the path to the git executable in your Visual Studio Code JSON settings file (File -> Preferences -> Settings) find and update the line - should look similar:
"git.path": "/usr/local/bin/git",
After an OS X update, I had to run xcode-select --install for GitLens to work.
Ran into the same problem after!
how I fixed it?
Step 1: Go to the Settings in vscode.
Step 2: Open settings.json.
Step 3: You need to find something like "git.path" in settings.json
Step 4: just add the directory path where git is installed in your system.
example : "git.path": "D:/Git/bin/git.exe"
Step 5: Restart your vscode.
Hope this helps.
Run
xcode-select --install it'll prompt you to install command line developer tools. Install the tools and installation restart your VScode.
You'll see git working once again in VScode
I ran into this problem after upgrading my macOS to Monterey.
It turned out that the xcode has been removed in the new update from my mac. Just tried the following suggested solution:
https://stackoverflow.com/a/52522566/11207358
VSCode 1.50 (Sept 2020) adds an interesting alternative with issue 85734:
Support multiple values for the git.path setting
I use VSCode in three different places; my home computer, my work computer, and as a portable version I carry on a drive when I need to use a machine that doesn't have it.
I use an extension to keep my settings synced up between editors, and the only issue I've encountered so far is that the git path doesn't match between any of them.
On my home machine I have it installed to C of course,
work likes to be funny and install it on A,
and for the one on my drive I have a relative path set so that no matter what letter my drive gets, that VSCode can always find git.
I already attempted to use an array myself just to see if it'd work:
"git.path": ["C:\\Program Files\\Git\\bin\\git.exe", "A:\\Git\\bin\\git.exe", "..\\..\\Git\\bin\\git.exe"],
But VSCode reads it as one entire value.
What I'd like is for it to recognize it as an array and then try each path in order until it finds Git or runs out of paths.
This is addressed with PR 85954 and commit c334da1.
with VSCode 1.60+
"git.enabled": true
git.path
I faced this problem on macOS v10.13.5 (High Sierra) after upgrading Xcode.
When I run the git command, I received the below message:
Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.
After running the sudo xcodebuild -license command, the below message appears:
You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.
Hit the Enter key to view the license agreements at '/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf'
Typing the Enter key to open the license agreements and typing the space key to review details of it, until the below message appears:
By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel]
The final step is simply typing agree to sign with the license agreement.
After typing the git command, we can check that Visual Studio Code detected Git again.
I have recently started with Visual Studio Code. I have this issue and just writing the exact path of the Git executable solves
the issue. Here is the code:
"git.path": "C:\Program Files\Git\bin\git.exe",
If you have multiple environments. You could include Git Path in the Visual Studio Code Workspace Setting. For Windows, depending on your setting, you could hit Ctrl + P, search for "settings". Open settings.json (or menu File → Preferences → Settings). Navigate to Workspace Settings. Find "Path" and add paths to Git bin and cmd folders.
Environments can have their own paths. I discovered this when I echoed my PC %PATH% on cmd. Git bin and cmd path where available, but when I was working on my project, echoed %PATH% did not have git and cmd folder. Adding them, as shown above, solved the issue.
Extra Notes:
On cmd, you can echo "%PATH%" and see if git bin and cmd folders are included. If not, you could concatenate using SETX PATH on, for example,
SETX PATH "%PATH%;Path_to_Git_bin;Path_to_Gt_cmd;"
This will make git available on local, root but not in some environments which comes with their own paths (SETX /M PATH "%PATH%;Path_to_Git_bin;Path_to_Gt_cmd;" would have though).
In case you have a long Path that is chopped off due to Path length (getting "Error: Truncated at X characters." message), you can increase the path length in RegEdit.
In "Search Windows", search for "regedit". Right-click to open as Administrator.
Go to Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
Right-click and modify. Change value data from 0 to 1
This will increase your path length. If it is already one, then I am not sure how to proceed from there :).
[9
The only way I could get to work in my Windows 8.1 is the following:
Add to system environment variables (not user variables):
c:\Users\USERNAME\AppData\Local\GitHub\PortableGit_YOURVERSION\bin\;c:\Users\USERNAME\AppData\Local\GitHub\PortableGit_YOURVERSION\libexec\git-core\;c:\Users\USERNAME\AppData\Local\GitHub\PortableGit_YOURVERSION\cmd\
This fixed the "it looks like git is not installed on your system" error on my Visual Studio Code.
Make sure git is enabled (File --> Preferences --> Git Enabled) as other have mentioned.
Make sure Gits installed and in the PATH (with the correct location, by default: C:\Program Files\Git\cmd) - PATH on system variables btw
Change default terminal, Powershell can be a bit funny, I recommend Git BASH but cmd is fine, this can be done by selecting the terminal dropdown and selecting 'set default shell' then creating a new terminal with the + button.
Restarting VS Code, sometimes Reboot if that fails.
Hope that helped, and last but not least, it's 'git' not 'Git'/'gat'. :)
In my case GIT was installed on my WIndows 10 OS and there was an entry in PATH variable. But VS CODE 1.52.1 still unable to detect it from terminal window but it was available in CMD console.
Problem was solved by switching terminal from PowerShell to CMD or Shell + VsCode restart.
I solved the same problem on MacOS with m1 pro processor by installing Git Lens Visual Code extension. The changed files were displayed after enabling the extension. Then I turned reloaded the VSCode and there was no changes, but once I run
git status
in terminal, it shows all the files, and all changes are tracked.
Faced this issue after updating macOS!
Installed git again using homebrew and it worked!
brew install git
FOR MAC
First, type
git
in the terminal and see what error you are getting.
Then:
If the error is related to Command Line tool!
Run:
xcode-select --install
And
Just go ahead and go through this answer, For Mac especially. Worked very easily for me.
https://apple.stackexchange.com/a/254381
Three years later, I ran into the same issue. Setting the path in user settings & PATH environment variable didn't help. I updated Visual Studio Code and that solved it.
First install Git onto your desktop, and then add the encircled extension in Visual Studio Code, as seen in the picture.
That helped me fix the same issue you have.
Open
C:\Users\nassim\AppData\Roaming\Code\User\settings.json
Comment any Git line there:
// ...
// "git-graph.integratedTerminalShell": "E:\\Apps\\Git\\bin\\bash.exe",
// "git.path": ""
//...
And add git.exe to the OS path.
Note for me: Fixing this Git error also fixed the npm error too. Since they are both defined in the path, if one fail, the remaining will fail as well.
Follow this :
1. File > Preferences > setting
2. In search type -> git path
3. Now scroll down a little > you will see "Git:path" section.
4. Click "Edit in settings.json".
5. Now just paste this path there "C:\\Program Files\\Git\\mingw64\\libexec\\git-core\\git.exe"
Restart VSCode and open new terminal in VSCode and try "git version"
In case still problem exists :
1. Inside terminal click on terminal options (1:Poweshell)
2. Select default shell
3. Select bash
open new terminal and change terminal option to 2:Bash
Again try "git version" - this should work :)
What worked for me was manually adding the path variable in my system.
I followed the instructions from Method 3 in this post:
https://appuals.com/fix-git-is-not-recognized-as-an-internal-or-external-command/
If git is missing after the OS update, in my case Big Sur, just literally: brew install git
I edited Path into System Environment and add "C:\Program Files\Git\bin" then restart Vscode. It's worked for me. I don't understand why I am using it normally then I have this problem. Maybe during the installation of something it causes that problem.
It worked for me just by installing git for windows, from this link https://git-scm.com/download/win
There was no need of setting environment variable or path.
Context:
I had installed VS Code, and github desktop, I cloned the repo using Github desktop.
When I opened repo, using VS Code, I saw this error.
I resolved by installing git for windows.

Xcode and git-lfs

I installed git-lfs using homebrew, and it works fine from the command line. I can still add text files in Xcode as well, but whenever I try in Xcode to add a file which should be tracked by git-lfs, there is no effect (the file stays "?" in Xcode's file list, and the command line confirms that the file was not, in fact, added). After some research, I tried adding ~/Library/LaunchAgents/my.startup.plist to setenv PATH /usr/local/bin but it had no effect.
How can I get Xcode to play nice with git-lfs?
There seem to be a problem with using git-lfs with Xcode. See this article:
http://gopalkri.com/2016/05/17/git-lfs-xcode-asset-catalogs/
Might be better off to stick with Git to commit your changes instead of doing it via Xcode.
We have a similar issue, our CI uses Xcode's git and not the homebrew one. So we needed to get git-lfs working in Xcode. This proved pretty simple: copying the git-lfs core file from the homebrew version into Xcode (you need to do this again every time you upgrade Xcode):
sudo ln -s `which git-lfs` /Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/git-lfs
Edited to highlight great improvement by #blackjack75.

Git and Xcode: Why do I have to agree to Xcode's T&Cs to use Git?

Git temporarily stopped working after I updated Xcode on my Mac. The message:
"Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo."
and then started working once I'd agreed to Xcode's T&Cs and installed the update.
Why, or should I say how, are the two linked?
I installed Git using the install.
Your git binary is provided by XCode (which is an easy way to get many command line tools packaged and maintained by Apple), and Apple wants you to accept their license before using any XCode component
If you don't like this, you can install it manually using Homebrew or similar. If you want to compile it yourself you will need a compiler for that. An easy way is using the one provided by XCode (see a pattern here?).
I've found that for my needs as a cross-platform Java-using-git developer the binaries provided by XCode are fine. This especially since they are automatically updated by Apple over time.
sudo xcodebuild -license will show you the license text of Xcode.
You have to agree its terms and condition at the end or you can just run the command given below.
sudo xcodebuild -license accept
P.S.- You are giving access to xcode.
In your terminal, run your git command as sudo
sudo git status
This will give you the option to view/accept the license agreements. Press enter to view it and press space until you get to the bottom. You can then type "agree" to agree to the license agreements. This will get rid of that message and you can use git again.
tl;dr try opening xcode and installing the plugins it suggests.
Even after I installed xcode, accepted the terms, and followed the developer tools prompt, it would continue to prompt me to install developer tools as if I didn't just do it. I eventually found a thread on reddit that suggested opening xcode and going through the recommended plugin installtion that comes up and that worked for me.

Cannot find FileMerge (opendiff tool) but I have xcode 4.6 installed

When I attempt to run FileMerge as a GUI for Opendiff, I receive an error:
$ git mergetool -t opendiff
Merging:
Gemfile
Gemfile.lock
...
Normal merge conflict for 'Gemfile':
{local}: modified file
{remote}: modified file
Hit return to start merge resolution tool (opendiff):
2013-12-26 20:00:20.248 opendiff[22367:e07] Couldn't find FileMerge
Gemfile seems unchanged.
Was the merge successful? [y/n] ^C
$
I have installed XCode 4.6.3 and Command Line Tools for Xcode April 2013. I am running OSX 10.7.5
I have tried solutions from the following two links with no success:
git diff with opendiff gives "Couldn't launch FileMerge" error
Is filemerge still available after Xcode 4.3 installation?
When I go to Xcode -> Open Developer Tool I do not see FileMerge in the list of options. There is a More Developer Tools link that takes me here: https://developer.apple.com/downloads/index.action?name=for%20Xcode%20-
How do I get FileMerge working?
FileMerge is located at within Xcode.
From the command-line:
cd /Applications/Xcode.app/Contents/Applications/
open .
Go into that directory once it opens:
Right-click on the app
Choose "Make alias"
Move that alias to your Applications directory
You're all set.
Strange. "XCode 4.5, where is FileMerge ?" suggests:
The FileMerge that is bundled with Xcode 4.5 doesn't work as a standalone application. I tried compressing it from the application bundle. I was able to expand it to show the FileMerge app on the desktop. But when I tried to run it I got an error saying it couldn't be opened.
Apple's developer downloads site has every version of Xcode. You could try trashing your current version of Xcode 4.5, downloading Xcode 4.5 from the developer downloads site, and see if FileMerge is there. If not, you can download Xcode 4.4 and see if that has FileMerge.
Indeed, I downloaded a fresh new install of XCode 4.5 and put my updated 4.4 to 4.5 upgraded version into the trash and I have now all the developer tools again, including FileMerge. Weird...
The other option, from that same thread:
Why not just install the Command Line Tools? That will give you the "opendiff" tool. Then, you create a little script like this one to make it useful and actually do a merge.
#!/bin/sh
# Get a hold of the last parameter.
eval LAST=\${$#}
# Now run opendiff with the previous version and the current version.
opendiff ${*} -merge "$LAST"
if you have xcode installed, then you can probably run the following from the command line to open FileMerge directly
open /Applications/Xcode.app/Contents/Applications/FileMerge.app/
Try reinstalling Xcode. I had the same issue and it fixed it for me! It appears the Merge utility got corrupt somehow.

Can't commit/update file in Xcode editor (SVN)

I'm having problems with Xcode's built in SVN manager.
I checked out a remote SVN repository and I want to commit the changes while I'm working in Xcode's editor. As seen on the screenshot, it shows the correct SVN flag in the Organiser window and also in the editor sidebar (M for modified etc.), but when I try to commit from within the editor, I get the error:
The operation could not be performed because no valid working copies were found.
Although commiting/updating etc. works fine in the Organiser window…
Any ideas why?
I had this exact same issue recently.
The solution for me was a simple restart of Xcode, and after that all the files were noted as being updatable via the right click "Source Control >" menu.
I encountered this myself today when trying out Git with Xcode for the first time. I created two demo projects with the "create a local git repository" option and they had the same problem. I was able to commit from the organizer window, but the main Xcode file view didn't seem to recognize git at all.
After quitting and restarting, I created a third demo with the git option, and the main window recognized the changes right off the bat - i.e showed the "M" beside a modified file.
I think Xcode subversion version is different from repositary version.
if you use other svn management tools like "cornerstone", you have to check versions.
Check subversion's version on Terminal
1.xcode subversion
/Applications/Xcode.app/Contents/Developer/usr/bin/svn --version
2.installed subversion
/usr/bin/svn --version
3.port installed version
/opt/local/bin/svn --version
check these versions and upgrade Xcode's svn binary.
This is what i did.
$ cd /Applications/Xcode.app/Contents/Developer/usr/bin
$ mkdir svn_backup
$ mv svn* svn_backup/.
$ ln -s /opt/local/bin/svn* .
and restart Xcode.

Resources