Thomas Kowalski
Thomas Kowalski

Reputation: 2184

git checkout doesn't update file

I have two Git branches master and develop. For various reasons, my develop branch got messed up and I'd like to get all the files from master to develop. I know it's not the right solution, but here's what I did:

git checkout master
cd ..
cp repo repo_master
cd repo
git checkout develop
cp -r ../repo_master/* .

The weird thing is that, after copying my files (which should be in the master's version) into my repo, running

git diff

Doesn't show anything. I don't get it. What is even weirder is that running

git diff master develop

Does show a lot of differences.

What am I doing wrong? Also, how should I do it?

Upvotes: 3

Views: 4734

Answers (4)

pegasuspect
pegasuspect

Reputation: 1031

You can undo your merge by using

git rebase -i --commiter-date-is-author-date HEAD~50

and remove the lines starting from the bottom of the commits list. Up until you reach your last commit before merge. save and exit the file.

Check your latest commits again to make sure its OK with

git log -n 10 --oneline

then finally override your remote

git push origin -f

Upvotes: 0

phd
phd

Reputation: 94397

git checkout develop
git checkout master -- .

The second command copies all files from branch master to the current worktree and index. Verify with git diff --cached and commit.

Upvotes: 0

Sarath S Menon
Sarath S Menon

Reputation: 2331

git checkout develop
git reset master

This will reset your develop branch to match the master branch exactly. All commits specific to the develop branch will be removed.

Upvotes: 1

Vadim Aidlin
Vadim Aidlin

Reputation: 326

If you don't need to preserve any changes in develop:

git branch -d develop will remove develop branch with it's contents.

git checkout -b develop will make a copy of current branch (in your case master) to the new branch named develop.

Or if you need anything to preserve in development:

git checkout develop

git merge master --no-ff then resolve conflicts, if any.

Upvotes: 2

Related Questions