简体   繁体   中英

Is it possible to git mv after push?

I did a git mv but for whatever reason after I pushed (multiple times) the file looks like it was deleted and there is a new file with the same name. Losing all of its history.

Is there a way to git mv after the push?

git doesn't really track file moves. When you move a file, git records it as a file at one path deleted, and a file at another path created.

The git mv command confuses a lot of users into believing that there is a way to actually record that a file moved, but there still is not; git mv is just an equivalent shorthand to moving the file with your OS (ie a shell command or drag-and-drop in windows) and then add ing the resulting changes.

Even though what's recorded is a delete and a create, many git commands do (by default) attempt to detect create/delete pairs that likely were really file moves. This is why git sometimes reports that a file moved and/or tracks the file's history through a move.

There are a number of things that affect how rename detection works. The most important one is that the file content not change too much in the commit where it moves - so it's often best, if practical, to do the move in a commit that leaves the file otherwise unchanged. But even then, rename detection isn't perfect and in some circumstances it can really struggle. (For example, a merge doesn't look at intermediate commits, so even if you're careful to always do renames in their own commit, a later merge may not see things correctly.)

Rename detection is not affected by whether yo uused mv , or by whether you pushed, or by filename similarity; only the similarity of the content is considered.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM