Get all files for one branch to my working branch.

My current branch is "feature\COMS-260". In the remote there is one branch "hotfix/4.6.7". For some reason, my branch code is mess up.

 

I want to use all files in branch "hotfix/4.6.7" to overwrite my local branch "feature\COMS-260".

 

How to do it?  I need Git commands or Sourcetree details.

4 answers

1 accepted

Your description does not give all needed information - as Seth asked, it's crucial whether some of your erroneous files from branch "feature\COMS-260" are already pushed to your remote repository and if someone else is tracking branch "feature\COMS-260" in this case.

Also the information is missing whether some commits on your branch "feature\COMS-260" should be preserved, or whether all commits on branch "feature\COMS-260" are a mess (and maybe deleted therefore).

 

I'll try to describe the solutions for the two thinkable situations (assuming some of your commits on branch "feature\COMS-260" should be preserved):

******* To be on the safe side, make a backup of your local repository in case of some failure ...*******

Case 1: erroneous files already pushed to branch "feature\COMS-260"

  1. being on branch "feature\COMS-260", do a "git pull" to be sure you are in sync with the remote repository
  2. identify the commit-ids of the commits containing the erroneous files
  3. do a "git revert ...." on those files to revert the erroneous commits
  4. this will lead to new commits - removing the changes of the used commits
  5. do a git push
  6. -> Now your erroneous commits are undone - your messed commits are still available, but there are also reverting commits, undoing this mess
  7. merge the changes from  branch "hotfix/4.6.7" to "feature\COMS-260"
  8. you're done a can start reimplementing your messed up branch code ...

 

Case 2: erroneous files NOT already pushed to branch "feature\COMS-260"

  • identify the last non messed up commit on your branch "feature\COMS-260"
  • CAVEAT: this commit-id MUST NOT be already pushed to your remote repository
  • being on branch "feature\COMS-260", do  a git reset --HARD commitId"
  •   -> your messed up commits are removed from repository (not visible anymore)
  • do a git pull to be sure to have all recent changes from remote
  • merge the changes from  branch "hotfix/4.6.7" to "feature\COMS-260"
  • you're done a can start reimplementing your messed up branch code ...

Has feature/COMS-260 been pushed to any remotes? If so, do you know whether any other developers have used it?

Yes, it has been to the remote. Nobody use it but me. I try to use the command "git reset --HARD commitId". commitid is for hotfix/4.6.7. Not sure if it is right.

That is one solution. If anyone else is tracking feature/COMS-260, they'll have some headaches.

Suggest an answer

Log in or Join to answer
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

256 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot