I have a branch (Branch A) which added about 300 files, I then merged this into master. The merge broke master so I removed all 300 files and committed the removal of these files. I then proceeded to go back into Branch A and fix the override, but merging this branch will not bring these files over as they have not been updated since the commit that deleted them. Is there a way to cherry-pick only the deleted files from a commit so I can bring them back?
Asked
Active
Viewed 981 times
1
-
While your prose is very clear, this question could still be improved by augmenting it with the minimum set of git commands that one can use to reproduce your exact problem, and the state you want the repository to be in. – merlin2011 Dec 02 '14 at 22:42
-
@merlin2011 I would like to add the 300 files back into my master(or develop) branch, preferably uncommitted. I used git add and git rm to add and remove files before commits. git merge to merge branch A into master. – Jtanacredi Dec 02 '14 at 22:50
-
Have you tried doing a 'git revert' on the commit that removed the 300 files? – Christopher Dec 02 '14 at 23:16
-
If your commit that removed the files is the most recent commit on master, you could also do something like 'git reset --soft HEAD^' – Christopher Dec 02 '14 at 23:23
1 Answers
3
On your master branch, get a list of deleted files since the previous commit.
git diff --name-status HEAD~1 | grep '^D' | cut -c 3- > /tmp/FileList.txt
Then, loop through the list of deleted files, and use git show
to pull the file data from the other branch.
for line in $(cat /tmp/FileList.txt); do git show OtherBranchName:$line > $line; done
Unfortunately, this does not handle file names with spaces, but we can use this answer to fix that problem.
IFS=$'\n'
for line in $(cat /tmp/FileList.txt); do git show OtherBranchName:$line > $line; done

Community
- 1
- 1

merlin2011
- 71,677
- 44
- 195
- 329