简体   繁体   中英

Does git cherry-pick -n and git commit equal to git add and git commit

For example, currently in branch master and status is clean:

A:

echo "test" >> README.md
git add README.md && git commit -m "asdf" ## commit id: AAAA

Then CommitDate and AuthorDate is same

B:

git checkout -b asdf
echo "test" >> README.md
git add README.md && git commit -m "asdf" ## commit id: BBBB
git checkout master
sleep 100 && git cherry-pick BBBB

Then CommitDate and AuthorDate is different

Instead of B, if I do C:

C:

git checkout -b asdf
echo "test" >> README.md
git add README.md && git commit -m "asdf" ## commit id: CCCC
git checkout master
sleep 100 && git cherry-pick -n CCCC && git commit -m "asdf"

Then CommitDate and AuthorDate is same

Except the hash id, are A and C same essentially? Is there anyway to figure out a commit is done by A or C ??

In C you are doing git cherry-pick -n CCCC and then git commit -m "asdf" the -n flag for cherry-pick denotes a no-commit which means that the cherry picked commit from the other branch are not committed but the necessary changes of the commit are made in the current working branch. So a new commit is made when git commit -m "asdf" is done.

-n or --no-commit : Usually the command automatically creates a commit. This flag applies the change necessary to cherry-pick the named commit to your working tree and the index, but does not make the commit. In addition, when this option is used, your index does not have to match the HEAD commit. The cherry-pick is done against the beginning state of your index.

This is useful when cherry-picking more than one commits' effect to your index in a row.

In B you are doing git cherry-pick BBBB without the -n flag and so the commit is automatically made with the commit from A.

So in C, the commit id refers to the commit made by C. In B, the commit id refers to the commit made by A.

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