开发者

ignoring merges in git

开发者 https://www.devze.com 2023-04-12 01:21 出处:网络
I\'ve not worked on a project quite some time and have just tried to pull the latest version. I can\'t remember the last time I\'d worked on the project but I\'d obviously had changes made to the Ma

I've not worked on a project quite some time and have just tried to pull the latest version.

I can't remember the last time I'd worked on the project but I'd obviously had changes made to the Master that I'd not pushed. As I've received s开发者_C百科ome conflict warnings.

Is there anyway to ignore my previous commits and pull down the master to overwrite my files?

What do you recommend I do in this situation?


I'm assuming that you've resolved the conflicts now, so that the first commit in git log is a merge commit.

Firstly, it's a good idea save where your old master branch was, just in case you want to go back. You can do that with:

git branch old-master master^

Then, if you want to reset your master branch to the version of master that you've just fetched from the origin repository, you can do that with git reset --hard:

# Make sure that you're on the master branch:
git checkout master

# Make sure the remote-tracking branches from origin are up-to-date:
git fetch origin

# Check that there's no output from "git status":
git status

# Now reset master to where origin/master points to:
git reset --hard origin/master

Note that git reset --hard is a dangerous command - it will throw away any uncommitted changes, which is why I suggest making sure that the output of git status is clean before using it.


I guess an easy way would be to backup your local master branch and recreate it... something like:

git fetch origin
git checkout master
git branch master -m old-master
git checkout -b master origin/master
git branch -D old-master (if you don't care about your commits there)

Hope it helps,

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号