git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: feature-request: git "cp" like there is git mv.

From
IDIgor Djordjevic <igor.d.djordjevic@gmail.com>
Date
Dec 18, 2017, 00:28 UTC
Message-ID
<45bf86e5-1cac-58ca-8ac1-0400b7efd568@gmail.com>
In-Reply-To
<CANaQPdK4xWek3PhiFZrURBBTgPBwsC3d3watd-cWVNBVZRqZRA@mail.gmail.com>
Hi Simon,
On 12/12/2017 11:53, Simon Doodkin wrote:
Show 6 quoted lines
> 
> please develop a new feature, git "cp" like there is git mv 
> tomovefile1 tofile2 (to save space).
> 
> there is a solution in https://stackoverflow.com/a/44036771/466363
> however, it is not single easy command.

While having `git cp` alongside `git mv` would make sense, I`m afraid that is not what you are really after, nor it would help in your case.

Looking at referenced "Stack Overflow" post[1], it tries to address `git blame` not following "file copy", where it does "file rename".

Proposed steps seem to be "solution" from your perspective, and while that may be absolutely valid and acceptable for your specific case, I would argue it`s the wrong approach in general - because `git blame` already supports what you want (just not by default), and making three additional, unneeded and possibly confusing commits (one being a merge), just to "bend" `git blame` to fit your (out of line?) usage expectations doesn`t seem right.

I would say a better direction might be using `git blame` "-C[<num>]" option[2], where desired effect is achieved without any artificial history fiddling.

Example being worth more than plain words, I`m providing a script[3] that demonstrates what I`m talking about :)

Regards, Buga
[1] https://stackoverflow.com/a/44036771/466363
[2] https://git-scm.com/docs/git-blame#git-blame--Cltnumgt
[3] Demo script showing how using (multiple) "-C" option(s), with 
    specified numeric value, can make `git blame` provide desired 
    information, recognizing "file copy" operation (line copy, actually, 
    but that is what we are really interested in, using `git blame`):
--- >8 ---
	git init
	echo a >A
	echo b >>A
	echo c >>A
	git add A
	git commit -m "create file A"
	git mv A B
	git commit -m "rename file A -> B"
	# ---
	# (A) regular flow
	cp B C
	git add C
	git commit -m "copy file B -> C"
	# ---
	# ---
	# (B) proposed "solution", https://stackoverflow.com/a/44036771/466363
	# git mv B C
	# git commit -n -m "rename file B -> C"
	# SAVED=`git rev-parse HEAD`
	# git reset --hard HEAD^
	# git mv B B-temp
	# git commit -n -m "rename file B -> B-temp"
	# git merge $SAVED # This will generate conflicts
	# git commit -a -n --no-edit # Trivially resolved like this
	# git mv B-temp B
	# git commit -n -m "rename file B-temp -> B"
	# ---
	echo
	echo '(1) blames B back to A, as expected:'
	git blame -- B
	# git blame shows that file B has a history (back to file A)...
	echo
	echo '(2) blames C only, missing B and A:'
	git blame -- C
	# ... while file C doesn't have a history
	echo
	echo '(3) blames C back to A, as expected:'
	git blame -C -C3 -- C
	# git blame shows that file C has a history (back to file A)
Previous: Junio C Hamano
Message 12 of 12 in “feature-request: git "cp" like there is git mv.”
  1. Simon DoodkinDec 12, 2017
  2. Johannes SchindelinDec 13, 2017
  3. Randall S. BeckerDec 13, 2017
  4. Jonathan NiederDec 16, 2017
  5. Stefan MochDec 31, 2017
  6. 1/2 Add test case for mv --dry-run to t7001-mv.shStefan Moch, Dec 31, 2017
  7. 2/2 mv: remove unneeded 'if (!show_only)'Stefan Moch, Dec 31, 2017
  8. Junio C HamanoFeb 7, 2018
  9. Stefan BellerFeb 7, 2018
  10. Stefan MochMar 18, 2018
  11. Junio C HamanoMar 19, 2018
  12. Igor DjordjevicDec 18, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.