简体   繁体   中英

How to move a git note to a different commit?

I've made a note on the wrong commit by mistake. Is there a easy way to move it in whole to a different commit?

I'm hoping for a way to semantically re-parent a note onto a different commit, But whatever is easiest would be great to know. I suspect the easiest option will be to copy paste the text with a desktop clipboard.

possibly the easiest way is to copy and remove the note:

For example, to move the HEAD notes to the previous commit,

# /!\ Be warned, this may be a destructive act

# git notes copy <source> <dest>
git notes copy HEAD HEAD^

# git notes remove <target>
git notes remove HEAD

PS notes are not automatically migrated when amending a commit.

Note that with Git 2.25 (Q1 2020), " git notes is more robust:

git note copy $original ought to copy the notes attached to the original object to HEAD , but a mistaken tightening to command line parameter validation made earlier disabled that feature by mistake.

See commit d58deb9 , commit 8af69cf (16 Oct 2019) by Doan Tran Cong Danh ( congdanhqx-zz ) .
(Merged by Junio C Hamano -- gitster -- in commit d4a98e7 , 10 Nov 2019)

notes : fix minimum number of parameters to " copy " subcommand

Signed-off-by: Doan Tran Cong Danh

The builtin/notes.c :: copy() function is prepared to handle either one or two arguments given from the command line; when one argument is given, to-obj defaults to HEAD .

bbb1b8a3 ("notes: check number of parameters to " git notes copy"", 2010-06-28, Git v1.7.1.1) tried to make sure " git notes copy" (with no other argument) does not dereference NULL by checking the number of parameters, but it incorrectly insisted that we need two arguments, instead of either one or two.

This disabled the defaulting to-obj to HEAD .

Correct it.

So now, git notes copy -f HEAD~2 should work as git notes copy -f HEAD~2 HEAD and correctly override HEAD notes with the ones from two commits before HEAD .

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