Merging the main branch into another Git branch does not delete files in the branch

So, I started using Git just a couple of weeks ago and ran into a problem for which I cannot find the correct answer. Actually the problem is quite simple.

  • At the beginning of the release, we had a master and he.
  • 3 branches were created from the master, let X, Y and Z.
  • About 50 files deleted from X were discovered and pushed back to the master, like 3 days ago.
  • The wizard correctly shows that these 50 files have been deleted.
  • Over the past 3 days, frequent intersectoral mergers between Y and Z have been observed.
  • In an attempt to get all the changes together, I first updated Y with all the changes in Z and finally tried to โ€œMergeโ€ the changes from X to Y, hoping to delete the files in my current branch (Y) that were originally deleted in X, and then transferred to Master.

However, merging does not delete the files, and I still have all of them in Y. However, when I go to the commit logs in SourceTree, I can clearly see the change set in which 50 files are deleted. Is file deletion merging?

+4
source share
1 answer

This seems like a caching issue. You had all the files in Y, but then they were deleted in X. For some reason, adding and deleting files tends to do strange things like this.

, ,

git rm --cached <file>

script, , , , , Y ( ):

#! /usr/bin/ruby

diff = `git diff --name-status X` #this will give you the name and status as (A, M, D, etc.)

# The output will look like this:
# A \t added_file
# D \t deleted_file
# M \t modified_file
# etc.

diff = diff.split #splits on new lines
deleted_files = diff.map do |entry|
  status_name_pair = entry.split('\t')
  return status_name_pair.last if status_name_pair.first == 'D'
end

deleted_files.each do |filename|
  `git rm --cached #{filename}`
end

, :

git rm --cached <dir>
0

All Articles