How to fix git conflicts with npm autogenerated files? - laravel

Making git pull I got conflict errors:
user#os:/proects/path$ clear
user#os:/proects/path$ git pull origin frontend-4
Password for 'https://usrename#github.com':
From https://github.com/clientname/project
* branch frontend-4 -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
package.json
public/js/app.js
public/mix-manifest.json
resources/js/components/common/Header.vue
resources/js/routes.js
Please commit your changes or stash them before you merge.
Aborting
user#os:/proects/path$ git stash
Saved working directory and index state WIP on main: e214191 Gigs pictures
making git stash I got conflicts with npm autogenerated files :
user#os:/proects/path$ git pull origin frontend-4
Password for 'https://usrename#github.com':
From https://github.com/clientname/project
* branch frontend-4 -> FETCH_HEAD
Auto-merging resources/js/routes.js
Auto-merging resources/js/components/common/Header.vue
Auto-merging public/js/app.js
CONFLICT (content): Merge conflict in public/js/app.js
Auto-merging public/css/frontend.css
CONFLICT (content): Merge conflict in public/css/frontend.css
Auto-merging package.json
Automatic merge failed; fix conflicts and then commit the result.
I tried to remove them first and run
npm run watch-poll
next
but I got errors :
user#os:/proects/path$ rm public/js/app.js
user#os:/proects/path$ rm public/css/frontend.css
user#os:/proects/path$ git commit -m "ignore compiled asset"
U public/css/frontend.css
U public/js/app.js
error: Committing is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
How can it be fixed ?
I do not need decision like setting in .gitignore rules:
/public/js/*
/public/css/*
as I need to upload my css/files to server, as I do not have npm installed on server.

Answer : Find lines that prevent auto merging and then do rest
The main problem for not commiting or pushing is because of the conflicts between files
Git can handle most merges on its own with automatic merging features. A conflict arises when two separate branches have made edits to the same line in a file, or when a file has been deleted in one branch but edited in the other
There are many tools to help resolve merge conflicts, such as :
git log
git reset
git status
git checkout
git reset
#How to identify merge conflicts
As we have experienced from the proceeding example, Git will produce some descriptive output letting us know that a CONFLICT has occcured. We can gain further insight by running the git status command
$ git status
On branch main
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: merge.txt
The output from git status indicates that there are unmerged paths due to a conflict. The merge.text file now appears in a modified state. Let's examine the file and see whats modified.
$ cat merge.txt
<<<<<<< HEAD
this is some content to mess with
content to append
=======
totally different content to merge later
>>>>>>> new_branch_to_merge_later
Here we have used the cat command to put out the contents of the merge.txt file. We can see some strange new additions
Think of these new lines as "conflict dividers". The ======= line is the "center" of the conflict. All the content between the center and the <<<<<<< HEAD line is content that exists in the current branch main which the HEAD ref is pointing to. Alternatively all content between the center and >>>>>>> new_branch_to_merge_later is content that is present in our merging branch.
#How to resolve merge conflicts using the command line
The most direct way to resolve a merge conflict is to edit the conflicted file. Open the merge.txt file in your favorite editor. For our example lets simply remove all the conflict dividers. The modified merge.txt content should then look like:
this is some content to mess with
content to append
totally different content to merge later
Once the file has been edited use git add merge.txt to stage the new merged content. To finalize the merge create a new commit by executing:
git commit -m "merged and resolved the conflict in merge.txt"
Git will see that the conflict has been resolved and creates a new merge commit to finalize the merge.
#Git commands that can help resolve merge conflicts
General tools
git status
The status command is in frequent use when a working with Git and during a merge it will help identify conflicted files.
git log --merge
Passing the --merge argument to the git log command will produce a log with a list of commits that conflict between the merging branches.
git diff
diff helps find differences between states of a repository/files. This is useful in predicting and preventing merge conflicts.
Tools for when git fails to start a merge
git checkout
checkout can be used for undoing changes to files, or for changing branches
git reset --mixed
reset can be used to undo changes to the working directory and staging area.
Tools for when git conflicts arise during a merge
git merge --abort
Executing git merge with the --abort option will exit from the merge process and return the branch to the state before the merge began.
git reset
Git reset can be used during a merge conflict to reset conflicted files to a know good state

Related

Git checkout fails on untracked working tree files after git mv

I have a problem with my local branches. When I am trying to do git checkout <branch> I get this error message:
error: The following untracked working tree files would be overwritten by checkout:
... (list of files)
Please move or remove them before you switch branches.
Aborting
I think that the reason is a fact, that in current branch I've renamed/moved some files with git mv.
All the files listed in this error message are listed with old path (i.e. path before moving / renaming action). Is there any way to work around this problem? I'd like to move to my master branch now, and merge it with current branch, so after that there should be no problem, yet for now, I don't know how to successfully switch branches (and then do a merge, if there might again be some problems).
Edit:
I was able to checkout using -f option, but the problem remains, because now I can't do merge, for the same reasons (actually, now the paths are the opposite, i.e. now error message contains new paths, that were used in database branch) and I don't know an option to force git to do this merging.
I am not sure, but probably the same solution would work for both checkout and merge problem.
Following #LutzBüch comment, I am trying to show exactly what happened in this repo.
I have branches master and database. The database branch worked only on a parts strictly related to database only. This part of code remained in a directory named let's say db. At some point, I had to change this dir name to DB, so I did some git mv's. Let's follow it from last merge, when everything still worked.
git checkout master
git merge database
git checkout database
git commit
{now the renaming happens}
git mv db/. tmp/.
git mv tmp/. DB/.
git commit {no other changes were made}
{added some renaming related changes, i.e. changed paths in 2 files}
git commit --amend
{now it's becoming the standard}
git commit {multiple times}
git checkout master {fails}
Last command failed with error message mentioned earlier. All files on the list had paths with the old dirname, i.e. db. After using git checkout -f master, when I tried to do merge I received paths with DB as the dirname.

Can't commit because someone else pushed, can't pull without discarding my changes in git

I am working with a friend on an iOS project, and we are using git for versioning, with Xcode. My friend has committed the changes, and I have my changes locally. When I try to commit my changes, I'm getting this error in Xcode:
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
When I try to pull, Xcode warns me about losing my local changes:
How can we simply merge the changes? I've used TFS before, and things were more much easy, we've checked in changes, and got latest, and if there was any conflict we could solve it. We don't need branching etc, we just need to keep our code in sync.
How can I solve this "deadlock" simply as possible? Or in other words, what is analogous to "just checking in/merging/getting latest in TFS" in git? Xcode built-in solutions preferred, without terminal.
UPDATE:
Here is what I get if I type git status at the terminal.
Cans-MacBook-Pro:myappname Can$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
You have unmerged paths.
(fix conflicts and run "git commit")
Changes to be committed:
modified: BigPostView.xib
modified: BigPostViewController.h
... (many others displayed here)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: myappname/Storyboard.storyboard
Cans-MacBook-Pro:myappname Can$
You should always be able to commit your changes, since that's a local operation. You'll get an error only when you try to push your commited changes.
In order to push your commit, you'll have to pull your friend's changes first.

GitBucket: error: Your local changes to the following files would be overwritten by merge

I have searched everywhere and tried various solutions but am still getting the error:
Your local changes to the following files would be overwritten by merge
i have nothing to commit as status tells me the following:
# On branch develop
# Your branch is behind 'origin/develop' by 1 commit, and can be fast-forwarded.
# (use "git pull" to update your local branch)
#
nothing to commit, working directory clean
So then I do a git pull, then get the following:
Updating 67020e6..6dd23de
error: Your local changes to the following files would be overwritten by merge:
app/filename.php
Please, commit your changes or stash them before you can merge.
Aborting
But as I have nothing to commit and if I do a git stash I get No local changes to save
So how can I fix the problem and download and update my local machine with my remote amends.
Bit of history incase:
I have to local machines one at home and work I have done the amends at home and pushed them and I am now trying to update my local work machine with these updates.
EDIT UPDATE
As I cannot answer my own question for a while I found what for me solved this answer:
on the branch I wrote:
git reset --hard
Then the pull worked.
While looking around i tried the following that seemed to fix my issue at the time.
While on the branch i wrote.
git reset --hard
Had you ever previously done git update-index --assume-unchanged <file>? That could be a potential reason for your situation.
To fix, you do git update-index --no-assume-unchanged <file>. Then you should be able to stash your changes and continue with the merge.
Faced exactly the same problem. I was used to CVS before I started exploring git. I think running git pull --rebase origin master is the way to go for the kind of workflow that you and I use.
Refer to https://www.atlassian.com/git/workflows#!workflow-centralized for a more detailed explanation. I definitely know the answer is somewhere in that article, but I didn't understand the article completely.

git on mac osx: how to push filename cases to origin?

I have changed the case of some directories in my git repository.
Then I pushed them and noticed the cases where not updated.
Then I found this question:
git mv and only change case of directory
I have followed the advice to use:
git add -A
git commit --amend -m 'updated cases'
git push origin
but instead of success the git server is returning:
To git#github.com:kyogron/example.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:kyogron/example.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
What can I now do to update the cases without breaking more in my git repo?
Regards,
bodo
PS: To avoid this issue in future you can use:
git config core.ignorecase false
You need:
git push --force
since you have rewritten the last SHA1 with your --amend, after using git mv.
It won't break your repo unless you have other collaborators having already pulled from your previous commit as explained in "How do I push amended commit to the remote git repo?".
(in that case, you would need other options for publishing your fixed commit)
On OsX, this answer does suggest (to avoid this issue):
git config --unset-all core.ignorecase
git config --system core.ignorecase false
The OP kyogron reports having found a working solution:
Create a new branch and checkout this new branch.
Then delete the .DS_Store file in the directory of the corrupted directory and rename it to new name.
Then remove wrong directory in the repository (you can view them with git ls-files) and commit this change.
Again remove the .DS_Store and now rename the directory to the lower case name you want with git mv

Github failed push

So to make a long story short, I've been working on a web app for the past few months. Recently I had to get a new laptop and cloned the repository from github onto my new machine... However whenever I commit changes to my app and attempt to use git push -u in the app's root directory i get the following message:
To git#github.com:acc/etc.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:acc/etc.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
but when I try git pull git#github.com:acc/etc.git master I get a message telling me that the pull was aborted.
From github.com:acc/etc
* branch master -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
config/routes.rb
test/fixtures/users.yml
Please, commit your changes or stash them before you can merge.
Aborting
so then i commit my changes using git commit -m 'fixing' and then attempt git pull again.
however this time I got messages stating that practically all my files had an "Auto-Merging CONFLICT"
am i totally screwed with this particular repository? I'm not really sure what to do since git is still somewhat new to me....
am i totally screwed with this particular repository?
No, but you will have to do a manual merge, since Git can't figure it out. git status will tell you which files need editing. The files themselves contain markers indicating where you should edit. When that's done, git push should work again.
If the changes aren't that big, consider making a copy of the entire folder/project in a different directory outside of the project, then git reset --hard HEAD will wipe out, erase and delete your recent changes.
You can then apply them again individually using your save3d copies for refernce.
Make sure sure you git add before git commit of course.
Finally if you get auto commit merge issues you can always just edit the files manually to resolve.

Resources