3

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?

4
  • You need to give us more information here. What got messed up? When did it happen, i.e. how many commits ago did it happen? The typical way to resolve a problem like this doesn't necessarily involve another branch, it just means resetting things back until you reach a stable point. Commented Jun 27, 2018 at 6:15
  • Well basically I use git flow and wanted to do a code modernization (it was using Java 5), so I got the terribly bad idea to treat this as a feature. When I merged back into develop, something made that the whole code was doubled (I guess git just estimated that it was the best way to handle the conflicts...) and that's how I got a small hundred classes not to compile anymore. I would have done resets but I was working on a feature branch that got merged (yeah, that was the problem) into develop while other changes were made on develop. Commented Jun 27, 2018 at 6:27
  • So I just thought, given the nature of my modifications, I would rather take back the master code - which is working, by definition of git flow - and put it back into develop to have a "fresh start" Commented Jun 27, 2018 at 6:28
  • Git doesn't work this way. You don't use move over a bunch of source code like this if the whole branch has a problem. Instead, just reset your develop branch to some commit from master. I can't give an exact answer, because your current state seems to be in a mess. Commented Jun 27, 2018 at 6:29

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Does that also delete all the commits I've made to develop?
Since branch is the set of commits, the answer is yes, it will delete all the commits from specified branch. If you, at any point, merged it with other branches, the code in those branches will stay as it is.
1
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.

Comments

0
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.

Comments

0

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.