Trying to use/learn git with a personal project. There’s only me and a remote git repo, a few commits, and I’m stuck in a failed merge. A lot of my files have Git merge conflict markup now too.
How do I tell git to just throw everything out, just use mine?
A specific example of how I got into the state I’m in:
echo A new file > myFile.txt # example file
git add myFile.txt # add file
git commit # commit changes
git push # push changes to remote repo
echo A conflicting edit > myFile.txt # oh, no, forgot some changes
git add myFile.txt # add again
git commit --amend # amend previous commit
git push # fails. Git suggests to do a pull first
git pull origin HEAD # "Automatic merge failed" Now what?
# Just use what I have locally!
There is a messy alternative that can break the repo for everyone else using the same remote origin. Only consider it if you’re the only one using it:
Explanation (now that I understand
gitbetter)The reason this happened is because amending commits changes ‘history’. Doing this locally is safe because it doesn’t affect anyone else. However, amending commits that have already been pushed does affect other repos, and is not safe.