Git merge and select local file in conflicts - python

I have an flask project which I have deployed to openshift, which I maintain locally. I deleted it from openshift and now would like to redeploy it. In the openshift gui, I created the a python app and grabbed the openshift git repo;
ssh://*******#myproject.rhcloud.com/~/git/myproject.git/
I changed origin to the new url with:
git remote set-url origin ssh://*******#myproject.rhcloud.com/~/git/myproject.git/
Now based on https://developers.openshift.com/en/knowledge-base.html#sync-a-new-git-repo-with-an-existing-git-repo I want to pull and merge.
I tried:
$ git pull ssh://*******#myproject.rhcloud.com/~/git/myproject.git/
From ssh://*******#myproject.rhcloud.com/~/git/myproject.git/
* branch HEAD -> FETCH_HEAD
Auto-merging wsgi.py
CONFLICT (add/add): Merge conflict in wsgi.py
Auto-merging .openshift/markers/README.md
CONFLICT (add/add): Merge conflict in .openshift/markers/README.md
Auto-merging .openshift/cron/README.cron
CONFLICT (add/add): Merge conflict in .openshift/cron/README.cron
Automatic merge failed; fix conflicts and then commit the result.
Basically at this point If I understand correctly, I want to choose my local files over the remote files in all cases. What is the best way to do this.
I'm suspecting a rebase may be in order but not sure.

If you want to choose your local files over the remote files, do:
git checkout --ours wsgi.py
git checkout --ours .openshift/markers/README.md
git checkout --ours .openshift/cron/README.cron
git commit -a

Related

Not transferring project to server when git push

I have a django project under development on my windows computer (dev-machine). I am using pyCharm for development.
I have set up a server (server-machine) running ubuntu. And now want to push my project to the server.
So in my project folder on the dev-machine I have done the git init:
$ git init
$ git add .
$ git commit -m"Init of Git"
And on the server-machine I have made a project folder: /home/username/projects
In this folder I init git as well
$ git init --bare
Back on my dev-machine, I set the connection to the server-machine by doing this
$ git remote add origin username#11.22.33.44:/home/username/projects
And finally pushing my project to server-machine by typing this command on my dev-machine
$ git push origin master
It starts to do ome transfer. And here's the problem.
On the server-machine when I check what's been transferred, it's only stuff like this
~/projects$ ls
branches config description HEAD hooks info objects refs
Not a single file from the project is transferred. This looks much like what the .git folder contains on the dev-machine.
What am I doing wrong?
What you see is the directory structure git uses to store your files and meta data. This is not a checked-out copy of the repository.
To check whether the data made it into the repository use git log in ~/project
Okay, so I understand now where I went wrong.
With git push I am not setting up the project.
To set up the project I need to do git clone.
This is how I did it.
1.
So I made a folder for git repositories on the server-machine. I called it /home/username/gitrepos/
2.
Inside there, I made a folder for my project, where I push the git repository into. So path would look like this for me /home/username/gitrepos/projectname/
3.
Being inside that folder I do a 'git init' like this
$ git init --bare
4.
Then I push the git repo to this location. First setting the remote adress from my dev-machine with this command. If adding a remote destination new use this:
$ git remote set nameofconnection username#ip.ip.ip.ip:/home/username/gitrepos/projectname
if changing the adress for a remote destination use this:
$ git remote set-url nameofconnection username#ip.ip.ip.ip:/home/username/gitrepos/projectname
To se with remote destinations you have set type this:
$ git remote -v
5.
Now go back to server-machine and clone the project into a project folder. I made a folder like this /home/username/projects/
When being inside that folder I clone from the gitrepo ike this:
$ git clone /home/username/gitrepos/projectname
Thank you all for the help! <3

heroku: no default language could be detected for this app

First time using Heroku. Trying to push. I have run the command:
heroku create --buildpack heroku/python
and it displayed
$ heroku create --buildpack heroku/python
Creating app... done, glacial-reef-7599
Setting buildpack to heroku/python... done
https://glacial-reef-7599.herokuapp.com/ | https://git.heroku.com/glacial-reef-7599.git
Stack trace:
$ git push heroku master
Counting objects: 129, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (124/124), done.
Writing objects: 100% (129/129), 69.06 KiB | 0 bytes/s, done.
Total 129 (delta 22), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: ! No default language could be detected for this app.
remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote: See https://devcenter.heroku.com/articles/buildpacks
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to pure-badlands-9125.
remote:
To https://git.heroku.com/pure-badlands-9125.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/pure-badlands-9125.git'
I've gotta be missing something.
I have added a requirements.txt to my root directory. It looks like this:
.git
.idea
projectapp
projectname
rango
db.sqlite3
manage.py
populate_rango.py
requirements.txt
Quick Solution
Goto heroku dashboard (https://dashboard.heroku.com/)
go inside app/project
click setting
scroll down little bit and click add build pack
select your desired buildpack (in my case i have selected heroku/nodejs).
TLDR;
Actually what heroku does is, it tries to identify what project you are deploying by looking at files in your project, such as if your project have package.json file it understands it is a nodejs project, if your project have requirements.txt file it understands it is a python project and so on, see this document to see to know what languages you can run on a heroku server
as you know to run a specific project such as a nodejs project in a computer node runtime must be installed in that computer otherwise you can not nodejs app in the computer, what heroku does it runs each of your app in a different container, it means in one container it is only one app is running and of course that container have installed nodejs, so if a container runs only one app it doesnt make sense to install all other runtimes in the container so container have only one runtime in my case it is nodejs. they have ofcourse other type of containers such as one type for python and that container have installed python runtime(of a specific version) so if my app gets installed in python container it will not work because my app in in nodejs. for this very reason somehow we need to identify the type of app in beginning to choose correct container type, mostly heroku automatically detect it but if it is failed to detect you have to tell explicitly either by going to their dashboard settings or through runtime file in your project, and as you may have noticed you have do this only once.
For future references, you must ensure that you are pushing the branch with your code to heroku master.
If you branched from your master branch and all your code is on a, say, develop, push that to the heroku master.
So instead of:
git push heroku master
You would do something like:
git push heroku develop:master
This question has important details on this How to push different local Git branches to Heroku/master
When deploying using Docker, ensure to set the stack of the app to container, as shown in the docs:
heroku stack:set container
You need to create a runtime.txt file. On the command line, in the same folder as your requirements.txt file, enter echo "python-3.5.1" > runtime.txt. Of course, make sure to switch the 3.5.1 with whichever version of Python you are using.
I can't remember how I fixed this but looking at the Date Modified in my files after I posted this question I created two files:
runtime.txt (thanks rurp) which contains:
python-3.5.2
Procfile which contains:
web: gunicorn projectname.wsgi --log-file -
This is a Django project and projectname.wsgi leads to a wsgi.py located at
projectname/wsgi.py
This contains:
import os
import signal
import sys
import traceback
import time
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "projectname.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
I had the same problem even after including runtime.txt. What worked was the inclusion of the requirements.txt
In my case I was in a sub git folder. When I looked at the root .git folder - the project indeed didn't had a package.json file - so heroku could not identify the webpack
I was running a django project and for me none of the solution above worked. So finally I gave up and went to the path thats mentioned in the error and it clearly stated that heroku needs either of the below file to detect a django project:
requirements.txt
setup.py
Pipfile
I than created a requirements.txt file by copying the contents of pip freeze in the root of the project and it worked correctly.
Faced this issue today and released I had named my requirements.txt as requirements.txt.txt(I literally named the file with .txt extension when it was already a text file), I also had a runtime.txt file with the content python-3.8.7.
Renaming the requirements.txt file correctly solved my issue.
I had 3 files in my root folder: code.py, requirements.txt and runtime.txt
Adding requirements.txt even as a blank text file did the trick for me, and I also ensured there was no build pack Heroku had added.
Heroku’s Python support extends to the latest stable release from the Python 2.x and Python 3.x series.
Today, this support extends to these specific runtimes:
python-2.7.13
python-3.6.1
try to change your python version in runtime.txt
Create Pipfile file in root folder and add python version and packages required for application. check sample file here
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
[packages]
django = "*"
gunicorn = "*"
django-heroku = "*"
[requires]
python_version = "3.6"
Also check Configuring Django Apps for Heroku
One more thing to note is to actually commit your changes to your git repo, before you can push them to Heroku.
You might have a requirements.txt setup locally, but if it's not committed to your repo, git push heroku master will not be able to locate it.
If you've tried some of the above answers and the problem still persists;
Ensure you are git "committing" in the right directory.
For instance, if your file structure is as follow:
/src
/...
manage.py
.gitignore
Pipfile/requirements.txt
Pipfile.lock
Procfile
runtime.txt
Ensure you're git adding, committing, pushing etc. from the root directory. Since we work mostly in the src/ or main_app_directory/ we tend to forget to change directory back to root before committing.
Hey guys so I have been stuck on this issue for the past two days and I found the solution to my problem. The first fix was renaming
"requirement.txt" to "requirements.txt"
then I removed the runtime.txt
cleared buildpacks using heroku cli set the buildpack to python
heroku buildpacks:set heroku/python
and Boom! it got uploaded an everything works now

Merging different alembic revision heads fails on heroku

I'm working to modify a cookiecutter Flask app.
locally I have deleted the migration folder and sqllite db a couple of times during development. I've pushed my chnages to heroku.
When trying to migrate the heroku postgresdb :
$ heroku run python manage.py db upgrade
.....
alembic.util.CommandError: Multiple head revisions are present for given argument 'head'; please specify a specific target revision, '<branchname>#head' to narrow to a specific head, or 'heads' for all heads
following http://alembic.readthedocs.org/en/latest/branches.html I tried:
$ heroku run python manage.py db merge heads
Running python manage.py db merge heads on myapp... up, run.9635
Generating /app/migrations/versions/35888775_.py ... done
Then I tried:
$ heroku run python manage.py db upgrade
Running python manage.py db upgrade on myapp... up, run.7021
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
....
"%s#head" % branch_label if branch_label else "head")
alembic.util.CommandError: Multiple head revisions are present for given argument 'head'; please specify a specific target revision, '<branchname>#head' to narrow to a specific head
, or 'heads' for all heads
How can I merge the revision heads into one and make sure this is synced with my development version?
I contacted heroku support and got the following back (which worked for me):
Hi,
To remove a folder from your local repository, git rm needs to be run. Could you please try something like below?
$ git rm -r migrations
$ git commit -m 'Remove migrations directory'
$ git push heroku master
To see differences between actual files and what are registered onto your local repository, git status may be useful.
Please let us know if you have any difficulty here.

Unique git url for github repo with multiple branches?

I'm looking at a flask app which I would like to import into an openshift project (https://github.com/lpolepeddi/intro-to-flask) . This contains a a series of 'checkpoints'(branches) as part of a tut. I want to grab the final code which is at https://github.com/lpolepeddi/intro-to-flask/tree/20_visibility_control for the starting point of a project . Is the a way to get a unique git url for this branch of the form
https://github.com/lpolepeddi/intro-to-flask.git
So that I can pull it in with a command like:
git remote add upstream -m master https://github.com/shekhargulati/flask-login-openshift-quickstart.git
Although as far as I know "single branch GitHub url" doesn't exist, you could just clone entire repo and later change branch:
git clone https://github.com/lpolepeddi/intro-to-flask.git
cd intro-to-flask
git checkout 20_visibility_control
or as stated in this answer, clone only one branch:
git clone --branch 20_visibility_control --single-branch https://github.com/lpolepeddi/intro-to-flask.git

Using Fabric to deploy current git branch to heroku

I'd like to shorten the process of deploying to Heroku (i.e. a git push)
I use git-flow to organise my codebase - so typically the process would be:
start a new feature branch
Do the coding
Push this branch up to my dev heroku instance - git push develop feature/somefeature:master)
Merge into the develop branch
Create a new release branch
Push this to the production heroku instance - git push production release/1.2.3:master
What I'd like to do is be able to run a Fab command like:
fab dev_deploy
which would just deploy whatever the current working branch is to my dev instance
and
fab prod_deploy
which would do the same but push to the production instance.
I could include some sanity checks here to make sure I'm inside a release branch etc.
my fab commands would do other things (like push static assets up to the right S3 bucket etc, run south migrate commands and so on)
So all I really want to know is how to get the current working branch as a variable inside fabric...!?
Thanks,
Guy
OK - a bit more digging got me this:
from fabric.api import local
my_branch = local('git rev-parse --abbrev-ref HEAD', capture=True)
which does exactly what I wanted.
import subprocess
my_branch = subprocess.check_output(['git','branch'])
or:
from fabric.api import local
my_branch = local('git branch')

Categories