Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Get all files for one branch to my working branch.

Hui Zhao July 23, 2015

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

1 vote
Answer accepted
Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 26, 2015

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 ...
0 votes
Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2015

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

0 votes
Hui Zhao July 24, 2015

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.

0 votes
Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2015

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events