diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 4f1ed05f126df1e452cf2e6707e9b3f6a9b40d72..6d12192582d881dd2868fe6e412f875d38de52c1 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -1152,12 +1152,15 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
     return !closingFailed;
 }
 
-Core::IEditor *EditorManager::pickUnusedEditor() const
+Core::IEditor *EditorManager::pickUnusedEditor(EditorView **foundView) const
 {
     foreach (IEditor *editor, openedEditors()) {
         EditorView *view = viewForEditor(editor);
-        if (!view || view->currentEditor() != editor)
+        if (!view || view->currentEditor() != editor) {
+            if (foundView)
+                *foundView = view;
             return editor;
+        }
     }
     return 0;
 }
@@ -1214,8 +1217,12 @@ Core::IEditor *EditorManager::placeEditor(Core::Internal::EditorView *view, Core
                 view->addEditor(editor);
                 view->setCurrentEditor(editor);
                 if (!sourceView->currentEditor()) {
-                    if (IEditor *replacement = pickUnusedEditor())
+                    EditorView *replacementView = 0;
+                    if (IEditor *replacement = pickUnusedEditor(&replacementView)) {
+                        if (replacementView)
+                            replacementView->removeEditor(replacement);
                         sourceView->addEditor(replacement);
+                    }
                 }
                 return editor;
             } else if (duplicateSupported) {
diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h
index 57406c8f0e122e52f81b9481cbc138cb7b00acc1..9890449fa4c731bb34e176fc6b75b8ecf1899f62 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.h
+++ b/src/plugins/coreplugin/editormanager/editormanager.h
@@ -273,7 +273,7 @@ private:
     void closeView(Internal::EditorView *view);
     void emptyView(Internal::EditorView *view);
     static void splitNewWindow(Internal::EditorView *view);
-    IEditor *pickUnusedEditor() const;
+    IEditor *pickUnusedEditor(Internal::EditorView **foundView = 0) const;
     void addDocumentToRecentFiles(IDocument *document);
     void updateAutoSave();
     void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable);
diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp
index 7d5fb64c8bdd7a77702fafa37787744a725f76a3..11106768c574d7cfc548b8463e034e2181d1ccab 100644
--- a/src/plugins/debugger/qml/qmlengine.cpp
+++ b/src/plugins/debugger/qml/qmlengine.cpp
@@ -413,18 +413,24 @@ void QmlEngine::beginConnection(quint16 port)
     if (host.isEmpty())
         host = QLatin1String("localhost");
 
-    if (port > 0) {
-        QTC_ASSERT(startParameters().connParams.port == 0
-                   || startParameters().connParams.port == port,
-                   qWarning() << "Port " << port << "from application output does not match"
-                   << startParameters().connParams.port << "from start parameters.");
-        m_adapter.beginConnectionTcp(host, port);
-        return;
-    }
-    // no port from application output, use the one from start parameters ...
-    m_adapter.beginConnectionTcp(host, startParameters().qmlServerPort);
+    /*
+     * Let plugin-specific code override the port printed by the application. This is necessary
+     * in the case of port forwarding, when the port the application listens on is not the same that
+     * we want to connect to.
+     * NOTE: It is still necessary to wait for the output in that case, because otherwise we cannot
+     * be sure that the port is already open. The usual method of trying to connect repeatedly
+     * will not work, because the intermediate port is already open. So the connection
+     * will be accepted on that port but the forwarding to the target port will fail and
+     * the connection will be closed again (instead of returning the "connection refused"
+     * error that we expect).
+     */
+    if (startParameters().qmlServerPort > 0)
+        port = startParameters().qmlServerPort;
+
+    m_adapter.beginConnectionTcp(host, port);
 }
 
+
 void QmlEngine::connectionStartupFailed()
 {
     if (m_retryOnConnectFail) {
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index 38211a706e10c042b9f49ab0d911a45b6eb32ce2..8dca382aa8f9fac52befaad4f01b42972d8e19c2 100644
--- a/src/plugins/git/gitclient.cpp
+++ b/src/plugins/git/gitclient.cpp
@@ -1130,6 +1130,7 @@ void GitClient::log(const QString &workingDirectory, const QStringList &fileName
                                                            enableAnnotationContextMenu,
                                                            args, fileNames));
     editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);
+    editor->setDiffBaseDirectory(workingDirectory);
 
     QStringList arguments;
     arguments << QLatin1String("log") << QLatin1String(noColorOption)
diff --git a/src/plugins/remotelinux/remotelinuxanalyzesupport.cpp b/src/plugins/remotelinux/remotelinuxanalyzesupport.cpp
index 1e4adc1ba55bdd12a1d18201f1ca4c52727cf5c1..3563053bce5a66b41a8cb4f3cdaf8a3b4e1a5e69 100644
--- a/src/plugins/remotelinux/remotelinuxanalyzesupport.cpp
+++ b/src/plugins/remotelinux/remotelinuxanalyzesupport.cpp
@@ -121,25 +121,26 @@ void RemoteLinuxAnalyzeSupport::startExecution()
 {
     QTC_ASSERT(state() == GatheringPorts, return);
 
-    if (d->qmlProfiling && !setPort(d->qmlPort))
-            return;
+    // Currently we support only QML profiling
+    QTC_ASSERT(d->qmlProfiling, return);
+
+    if (!setPort(d->qmlPort))
+        return;
 
     setState(StartingRunner);
 
     DeviceApplicationRunner *runner = appRunner();
     connect(runner, SIGNAL(remoteStderr(QByteArray)), SLOT(handleRemoteErrorOutput(QByteArray)));
     connect(runner, SIGNAL(remoteStdout(QByteArray)), SLOT(handleRemoteOutput(QByteArray)));
-    if (d->qmlProfiling)
-        connect(runner, SIGNAL(remoteProcessStarted()), SLOT(handleRemoteProcessStarted()));
-    QString args = arguments();
-    if (d->qmlProfiling)
-        args += QString::fromLocal8Bit(" -qmljsdebugger=port:%1,block").arg(d->qmlPort);
-    const QString remoteCommandLine = d->qmlProfiling
-        ? QString::fromLatin1("%1 %2 %3").arg(commandPrefix()).arg(remoteFilePath()).arg(args)
-        : QString();
+    connect(runner, SIGNAL(remoteProcessStarted()), SLOT(handleRemoteProcessStarted()));
     connect(runner, SIGNAL(finished(bool)), SLOT(handleAppRunnerFinished(bool)));
     connect(runner, SIGNAL(reportProgress(QString)), SLOT(handleProgressReport(QString)));
     connect(runner, SIGNAL(reportError(QString)), SLOT(handleAppRunnerError(QString)));
+
+    const QString args = arguments()
+            + QString::fromLocal8Bit(" -qmljsdebugger=port:%1,block").arg(d->qmlPort);
+    const QString remoteCommandLine =
+            QString::fromLatin1("%1 %2 %3").arg(commandPrefix()).arg(remoteFilePath()).arg(args);
     runner->start(device(), remoteCommandLine.toUtf8());
 }