I face a merge conflict when I would like to rebase the develop branch against my feature branch. I use IntelliJ Idea to execute individual Git commands. Let's say I have 3 pushed commits and I want to squash and rebase them using --interactive mode.
I select all three commits, I select squash, do some rewording, and hit Rebase.
The process fails and an Excel file that appears in the Git panel among Changes and on the diff panel, says the contents are the same. I can only abort or retry the rebase, but continuing doesn't make sense as the change always prevents me to continue.
Here is the console output:
12:50:42.385: [myapplication] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false -c core.commentChar= rebase --interactive develop
Rebasing (1/2)
error: Your local changes to the following files would be overwritten by merge:
excel-file.xlsx
Please commit your changes or stash them before you merge.
Aborting
hint: Could not execute the todo command
hint:
hint: fixup 37d1fc57dff9c7e9a312c88cf78c176cb71dbb47 CommitMessageIsHere
hint:
hint: It has been rescheduled; To edit the command before continuing, please
hint: edit the todo list first:
hint:
hint: git rebase --edit-todo
hint: git rebase --continue
Could not apply 37d1fc5... CommitMessageIsHere
Is there a trick to overcome this obstacle? Is possible to somehow force ignoring and skipping such merge conflict?
You started your rebase with un untracked copy of excel-file.xlsx, and when git met a commit which included the action "create a new excel-file.xlsx file", he stopped.
You have to somehow put aside this untracked version before proceeding.
The simplest way is:
rename that file on disk:
mv excel-file.xlsx excel-file.xlsx.tmp
run git rebase --continue:
either IntelliJ has a button which looks like "proceed with the rebase", or you can run this command from the command line,
once the rebase is complete:
you can compare the contents of both files, and decide what the correct action is -- update the tracked version, delete the tmp file ...
Related
I'm trying to close an old branch that is no longer used but every time I do the close command on this branch it says a new head is created. Other branches do not have this issue. Does anyone know what my issue could be?
jchan#jchan-Z170N:~/eclipse-workspace/filtec-src/src$ hg --version
Mercurial Distributed SCM (version 3.7.3)
...
jchan#jchan-Z170N:~/eclipse-workspace/filtec-src/src$ hg update -r version1.5.11 -C
1367 files updated, 0 files merged, 6050 files removed, 0 files unresolved
jchan#jchan-Z170N:~/eclipse-workspace/filtec-src/src$ hg commit --close-branch -m "closing legacy branch"
created new head
when i query the list of branches again this branch keeps showing up:
hg branches
...
version1.5.11
Why is this? I am using mercurial command line on Ubuntu 16.04.
Found that I was able to use the tortoise Hg tool "thg" to search and find all the head commits on the miss behaving branch and then merge them all together. After merging all these similar heads together I was able to close the final head and now this branch no longer comes up in the hg branches query.
I'm following this git stashing guide but when I try to un-stash by using the command
$ git stash show -p stash#{0} | git apply -R
or
$ git stash show -p | git apply -R
I keep getting these errors
error: patch failed: app/scripts/app.js:20
error: app/scripts/app.js: patch does not apply
error: patch failed: app/views/main.html:34
error: app/views/main.html: patch does not apply
How do I get past this error?
When I do $git stash list it shows stash#{0}: WIP on my_branch: dc19ed5 My Commit
If you've modified the code after applying a stash you won't be able to reverse the applied stash in the manner suggested by that guide. This is because git can no longer apply the patch specified by the stash as the code doesn't look how it expects any more.
You could fix up the patch output by git stash show -p stash#{0} manually, but unless the changes made since the patch was applied were very minor I wouldn't recommend it.
These steps should allow you to get to the state you want, there may be a better way so I'll update this answer if I think of it:
Stash your code in the state it's currently in
Apply the previous stash and commit
Apply the new stash and commit (there may be some merge conflicts which you'll have to fix manually)
Revert the first commit
This should leave you with a commit that only has your new changes. You may want to do this on a branch.
This question already has answers here:
How to modify existing, unpushed commit messages?
(27 answers)
Closed 8 years ago.
I use Git in command line with linux and not as a graphic client.
I wrote the wrong thing in a commit message.
How do I change the message?
If it is the most recent commit, you can simply do this:
git commit --amend
This brings up the editor with the last commit message and lets you edit the message. (You can use -m if you want to wipe out the old message and use a new one.)
And then when you push, do this:
git push --force <repository> <branch>
Be careful when using push --force. If anyone else has pushed changes to the same branch, those changes will be destroyed.
Anyone who already pulled will not get an error message, and they will need to update (assuming they aren't making any changes themselves) by doing something like this:
git fetch origin
git reset --hard origin/master # Loses local commits
To change a commit message of the most recent (unpushed) commit, you can simply use
git commit --amend -m 'new message'
To change messages of (unpushed) commits further in the past:
git rebase -i [COMMIT BEFORE THE FIRST YOU WANT TO EDIT]
If it is the last patch you commited from your repo, it will be on the top of your git log.
In that case, just run the below command and push the same once again.
git commit --amend
Than, modify your message and push the same. Since you are not modifing any change in file, it should not give any error.
If some patches have already come on the top of yours. Then you have to check merge dependencies also. In this case,
either git reset --hard your commit
run git commit --amend
Push it back
or
git commit --amend -C commit-id
push it back
But you need to consider merge dependencies also.
**
And more best approach will be:
**
You can use git rebase, for example, if you want to modify back to commit xyz, run
$ git rebase --interactive xyz^
In the default editor, modify 'pick' to 'edit' in the line whose commit you want to modify. Make your changes and then commit them with the same message you had before:
$ git commit -a --amend --no-edit
to modify the commit, and after that
$ git rebase --continue
to return back to the previous head commit.
When I try to perform a patch using:
git am 0001-someFile.patch
but I get this error:
error: patch failed: src/***/file.c:459
error: src/***/file.c: patch does not apply
Patch failed at 0001 someFile.patch
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".
I am trying to manually merge the conflicts using:
git mergetool --tool=meld
But I am getting:
No files need merging
How can I solve this problem?
I am getting the name of the file which holds the error, but have no idea about the line (it's a big file)
Maybe there is a better way to perform such patching?
I'm in charge of handling all patching at my work. I've had this happen many times. A patch cannot be merged. The reason this is happening is because the master branch has changes that the patch did not take into account, which prevents it from patching correctly. From all my experience, this could be caused by several things:
The person who made the patch failed to pull the master branch and rebase master onto their development branch.
Between the time that the person pulled and the patch was applied enough changes were made to the master branch to stop the patch from applying due to too many conflicts.
The person patched incorrectly.
Here is the flow I've had the most success with. (This is assuming the person is developing on a branch other than master)
Make sure you've added all files and commited all changes.
git checkout master
git pull
git checkout {development branch}
git rebase master (this will bring the development branch up to speed with master)
git checkout -b {submission branch} master
git merge --squash --no-commit {development branch}
git commit -am "Commit Comment Here" (NOTE: This commit comment will be the name of the patch)
git format-patch origin..HEAD
That makes sure your patch is up to date with the origin master branch. Send that patch and hopefully the patch is applied before too many changes are made on the master.
You need to do a 3-way merge:
git am -3 0001-someFile.patch
git mergetool -t meld
Here is the scenario:
On a smallish Ubuntu web server I have a git server running. The website is checked out from git repository. I had a bulk of changes that I added and committed. Git diff showed 50+ code files updated and 20000+ image files. I did not paid much attention to this thinking these should be ignored, my fault. A bit stupid but I thought it was quickest to just commit all changes as a bulk. Let's call it commit A
# Commit A
git add .
git commit -m "Changes so far in this year"
I discovered that I forgot to exclude working/output files (huge number of generated images). Other than these files (around 20000) I had about 50+ files with code changes.
After reading online and git manual I understood that best bet was to update .gitignore and generate a list of files to remove and remove cached. This should remove from commit but not the local folder. Let this be commit B
# Commit B
vi .gitignore
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
git add .
git commit -m "Cleanup of generated files from commit history"
Trouble is that now my git push fails with following error
git push origin master
Counting objects: 19219, done.
error: pack-objects died of signal 9
error: pack-objects died with strange error
error: child process died of signal 9
error: died of signal 9
error: failed to push some refs to '/srv/gitrepositories/xxxx.git'
Answers on this question about error 9 suggests it might be due to git running out of memory.
My options?
Is commit A & commit B made up of huge
number of objects, which looking at the count above it seems?
Is there a better way to clean this mess up with possible option to remove commit A & commit B altogether from history and get my changes intact?
Idealy I want to go back to stage where my git diff reports only the 50+ code files. Images are now ignored by .gitignore
Can I delete a git commit but keep the changes? Is this what it sounds like? Can I do it twice for both commit A and commit B?
Yes, you can use git reset HEAD~2 to clear the last 2 commit from history permanently while keeping the changes in the working directory, then git push -f to force push your changed history to the remote.
If your repo is shared with others it's not advisable to change your commit history.