1

I have a local repo where I have put a file 'notes' where i keep some text about my own observations and concerns. When I commit and push to the remote repo I must remove the file. Before I initially made the commit I ran git rm --cached notes but this apparently did not work because after I pushed the notes file appeared on github.

So what I did locally was run rm again (somehow it works this time) and do a
git commit --amend and then git show --stat --oneline HEAD and I notice notes has been removed.

But now in order to push I must merge the remote changes into my local repo because

Updates were rejected because the tip of your current branch is behind its remote counterpart.

So I run a pull but this fails as well with:

CONFLICT (modify/delete): notes deleted in HEAD and modified in 5bfdf....

What do I need to do to simply delete the notes files from this commit both locally and remotely?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Alex Bollbach
  • 4,370
  • 9
  • 32
  • 80

3 Answers3

1

When I commit and push to the remote repo I must remove the file

If you don't want to commit the file but still to able to modify it locally use

https://git-scm.com/docs/git-update-index

--assume-unchanged

git update-index --assume-unchanged <path>

In case you need to print out list of files marked with the --assume-unchanged flag:

git ls-files -v|grep '^h'

enter image description here


How to solve your problem?

What do I need to do to simply delete the notes files from this commit both locally and remotely?

First of all pull any changes from the server and then do your changes.

git pull origin <branch>
git add -A .
git rm --cached notes
git commit -m ...
git push origin <branch name>
Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • `Pull is not possible because you have unmerged files. Please, fix them up in the work tree, and then use 'git add/rm ' ` – Alex Bollbach Mar 20 '16 at 06:15
  • If so it means that you have committed the notes file to the repo in the past. remove it again with the `git rm...` and commit this change. now you will be able to push/pull – CodeWizard Mar 20 '16 at 06:17
  • A conflict can only occur on files which are already in the repo. Fix the conflict by removing the file from in the index, and then when you will add it it will be removed, commit and then pull. If you want to abort the merge and remove it first use `git merge --abort` – CodeWizard Mar 20 '16 at 06:19
  • i already ran `rm -cached` on the notes file and did a `commit --amend` and tried to push but got `failed to push refs..` – Alex Bollbach Mar 20 '16 at 06:20
  • do a git pull before pushing – CodeWizard Mar 20 '16 at 06:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/106827/discussion-between-codewizard-and-user5797668). – CodeWizard Mar 20 '16 at 06:26
  • You cant push if your branch is not up to date with the remote. If you still have problems, rename your current branch, checkout the original again and then add your changes and push – CodeWizard Mar 20 '16 at 06:28
0

Of course there are my friends , check out these two links:

-An article about solving git conflicts. Has a specific paragraph for you issue.

-Another post about the same issue with loads of suggestions.

My own suggestion is to either get a merge tool or use the the existing GIT tool which will make your life much easier.

Good luck

Community
  • 1
  • 1
H.B
  • 107
  • 7
0
  1. move notes file to a temp location.
  2. git pull. This will pull notes from repo.
  3. git rm -f notes
  4. git commit
  5. git push

Basically aim is to bring local and remote in sync and then deleting "notes" file.

Sanj
  • 3,879
  • 2
  • 23
  • 26