git merge untracked branch removes code - ruby-on-rails

I am working with a team on git and my local untracked production branch is missing lines of code from a team member.
My local master branch is tracked on the remote/origin/master and it shows all the code.
The local production branch was checkedout from remote/origin/production with this command
git checkout production
After finishing the development branch I did:
git checkout production
git merge development
I deploy to server and then
git checkout master
git merge development
git merge production
git push origin master
Later I find out that production branch and server are missing some lines of code (while master is ok)
I thought this could be caused by the fact that the remote branch was not tracked with git checkout --track production
Then I found that git diff master..production does not show differences, but analyzing the production branch I can find this commit relative to the merge of the development branch:
git show b17832a
commit b17832ae656f1bd43ebf837934f16b7d1f6efa33
Merge: a9bd850 0873d56
Merge branch 'development'
and here I can find the removed line of code
git diff a9bd850..0873d56 file.rb
diff --git a/file.rb
index e0d1d1b..2343d92 100644
--- a/file.rb
+++ b/file.rb
## -49,12 +49,6 ## angular.module('sp').directive 'spPlayer', [
some text and below I can find
- my missing line of code
- is showing here
how can I fix the production branch and push the change? My commit on master have already been push to the remote.

You mentioned:
Later I find out that production branch and server are missing some lines of code (while master is ok)
Update local production with master then push to remote production (origin/production).
$ git checkout production
$ git merge master
$ git push origin production
Update remote master (origin/master)
$ git checkout master
$ git push origin master
N.B. the issue is solved discussing in OP's comment section actually.

Related

Reset master to an empty state

I created a new Rails app and pushed the code to Github directly from master (first commit in the repository). However I made a mistake, I didn't want to commit this new Rails app directly from master, but instead create a new branch from master and push the new Rails app from this new branch.
Therefore, I'd like to:
Delete the commit from master in Github(remote), so master is EMPTY
create a new branch from master and add the previous commit that was in master into this new branch.
push it to Github.
Delete the commit from the master in Github(remote), so master is EMPTY
You can create an orphan branch - orphan branch is branch without any history
# Create "clean" branch
git checkout --orphan <name>
# remove all existing content if you wish
git clean -Xdf && git clean -xdf
create a new branch from master and add the previous commit that was in master into this new branch.
few options:
# Option 1 - Start your branch from the last desired commit
git checkout -b <name> <SHA-1>
# Option 2 - Set your branch to the desired commit
git reset <SHA-1> --hard
# Add the required commit on top of your branch
git cherry-pick <SHA-1>
push it to Github.
# force the update of the new branch
git push <origin> master -f
Please create a new branch from the master with the following command,
git checkout -b branch_name
After that checkout into your new branch and push it to Github.
Now go to the master branch and remove the last commit and push it to Github
You can also try the following steps with your repository:
git checkout master: make sure you are in master.
git checkout -b my-fancy-new-branch: create your new feature branch.
git checkout master: switch back to master
git reset --hard rootcommit: reset master to the state before your own commits.
optional and if you have a remote you pull from: git pull --ff (if this fails because the pull is not fast-forward, you have to reconsider rootcommit. It contains some of your work)
I tried to do this on my test repository, it appears to work.
I have taken a reference from this answer, that can help in finding other approaches too.

How to clone the code from master branch in Bitbucket?

I am using Bitbucket in my project. When I am cloning the code on my local machine with my branch URL I am getting the updated code of my branch and unable to see the changes in the other branches. How to clone the updated code from all branches in Bitbucket?
First check which branch you're on and if you have already checked out the master branch:
git branch
You should see something like, although the names will probably be different:
dev
master
* test
Switch to the master branch. If master WAS NOT listed in the previous step run the following:
git checkout -b master origin/master
If master WAS listed just run:
git checkout master
You will now be on the master branch. Now do a git pull for the latest updates.

Pull changes from github to local rails files

So I know how to update the repository with my files (the master one at least). And I know I can create a local branch with
$ git checkout -b [branch_name]
but that only creates it on the local git...how do i checkout a branch from the master on github and also overwrite files in my app directory, so I can update my project with the work of other people
Do you mean to ask, how to reset master on your local machine to that of the master on the origin?
If so:
Fetch all remote/origin changes and then hard reset your local master to origin/master's head:
$ git checkout master
$ git fetch --all
$ git reset --hard origin/master

Heroku: ! [rejected] master -> master (non-fast-forward)

I get and error whenever I try to push rails app to heroku. What do I do to fix this? I did git init, git add ., git commit -m "complete", and git push heroku master
To https://git.heroku.com/shuabe.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://git.heroku.com/james.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Someone has committed so you have to update your brach width git pull in order to be up to date.
git fetch --all --prune
git pull origin master
Fetch will update all your branches & pull will grab the latest content into your master branch.
If you would read the error it explaining you what to do.
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes
More detailed
You are trying to push to a remote branch which has some commits that you don't have them locally in your branch. In order to push to a non-fast-forward repository you branch must have the latest updates from the remote repository.
How to grab latest updates?
git fetch --all --prune
This command will grab all the content of the whole remote repository and will update the internal git storage (pack & index files) inside the .git folder.
git pull origin master
This command will fetch & merge the remote branch into your local branch (master) and after that you will be able to push your changes.
And also you can use force argument.
git push --force heroku yourbranch:master
I fixed by:
git pull heroku master
After that, console shows:
From https://git.heroku.com/myweb
* branch master -> FETCH_HEAD
Auto-merging views/layout.hbs
CONFLICT (content): Merge conflict in views/layout.hbs
Auto-merging views/ads/list.hbs
Auto-merging controllers/users.controller.js
CONFLICT (content): Merge conflict in controllers/users.controller.js
Auto-merging config/db.config.js
CONFLICT (content): Merge conflict in config/db.config.js
Automatic merge failed; fix conflicts and then commit the result.
I accepted every change, and after that:
git push heroku master
git pull heroku main
Then
git push heroku main
The above commands worked for the question.
Then I got another error: your account has reached its concurrent builds limit (pre-recieve hook declined).
I resolved that with:
heroku restart
PS: git pull heroku main then git push heroku main should work straight up for heroku accounts that haven't reached builds limit.

Git merge locally messed up. Gemfile disappeared and rails server does not start

Did a Merge Branch locally in working-copy with master. After merging, switching back to master displays HEAD, instead of master as it was before. Also errors pops up when start rails server with rails server, saying no bcrypt file to load. Also Gemfile disappeared from the root subdir.
Ran bundle install and did not help.
Here is the output of git branch and git rebase.
$ git branch -a
* (no branch)
master
working_copy
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/working_copy
$ git rebase --abort
No rebase in progress?
Any idea about how to fix? Thanks
As long as everything was commited, you should be fine:
git checkout working_copy
git reset --hard `git log --pretty=format:'%h' -n 1`
That will hard reset to your last commit on the branch. From there, you can start the merge all over again.

Resources