Consider the following Git graph
master: A - B - C - D - E*
\ /
feature: X - Y - Z
I want to make a new commit in master, E, such that E precisely matches Z. In other words, any changes that may have been made in commits C and D are completely discarded. However, I would still like to retain the property that doing git checkout HEAD~1
in master would checkout D.
Doing git checkout master; git reset --hard feature
gets the working directory in the proper state (i.e., all tracked content precisely matches that of Z). However, is does not leave the history in the way that I intend.
Doing something like git checkout feature -- .
almost works, but retains any files created in B or C, so it won't always precisely match the state of Z.
Doing something suggested in other responses to similar questions seems quite inefficient, as it involves several different checkouts and merges and is something I need to specifically avoid, as this operation will be done frequently and on rather large repositories.
It seems like years ago someone asked a similar question and got this response: https://stackoverflow.com/a/4912267/927604
Part two of this question is: Seriously? Unless I'm missing something major, why is this not obvious to do?
Thanks!