gpt4 book ai didi

git - 使用 git 移动文件时丢失历史记录

转载 作者:行者123 更新时间:2023-12-03 08:06:34 24 4
gpt4 key购买 nike

阅读 question 的答案后关于移动 git 跟踪的文件,如果您移动 git 正在跟踪的文件,历史记录不应受到影响。但这不是我的经验,那么我做错了什么?这是我的控制台日志

C:\scripts\Python\Cyren>mkdir archive

C:\scripts\Python\Cyren>dir
Volume in drive C has no label.
Volume Serial Number is 7C59-18A2

Directory of C:\scripts\Python\Cyren

08-May-22 22:44 <DIR> .
08-May-22 22:44 <DIR> ..
08-May-22 22:43 <DIR> archive
31-Mar-22 19:11 1,878 categories.csv
31-Mar-22 17:57 1,886 categories.txt
30-Mar-22 21:19 14,557 categories.xlsx
29-Apr-22 16:23 19,274 CyrenDopplerAPI.py
06-May-22 12:35 14,585 CyrenDopplerEnv.py
29-Apr-22 16:16 17,672 CyrenSample.py

C:\scripts\Python\Cyren>git log CyrenDopplerAPI.py
commit 4f440a2c132053ebe9c76a16e90abc1dd845d262
Author: Siggi@Reba <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="75061c12121c3506000510071210101e5b0006" rel="noreferrer noopener nofollow">[email protected]</a>>
Date: Thu May 5 15:38:58 2022 +0000

rename

C:\scripts\Python\Cyren>git mv CyrenDopplerAPI.py archive

C:\scripts\Python\Cyren>dir
Volume in drive C has no label.
Volume Serial Number is 7C59-18A2

Directory of C:\scripts\Python\Cyren

08-May-22 22:48 <DIR> .
08-May-22 22:48 <DIR> ..
08-May-22 22:48 <DIR> archive
31-Mar-22 19:11 1,878 categories.csv
31-Mar-22 17:57 1,886 categories.txt
30-Mar-22 21:19 14,557 categories.xlsx
06-May-22 12:35 14,585 CyrenDopplerEnv.py
05-May-22 18:24 109 Infile.txt
06-May-22 12:35 <DIR> Logs
5 File(s) 33,015 bytes
4 Dir(s) 484,630,781,952 bytes free

C:\scripts\Python\Cyren>git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: CyrenDopplerAPI.py -> archive/CyrenDopplerAPI.py
renamed: CyrenSample.py -> archive/CyrenSample.py
C:\scripts\Python\Cyren>git commit -m "cleanup and archiving"
[master 1240039] cleanup and archiving
2 files changed, 0 insertions(+), 0 deletions(-)
rename Cyren/{ => archive}/CyrenDopplerAPI.py (100%)
rename Cyren/{ => archive}/CyrenSample.py (100%)

C:\scripts\Python\Cyren>git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)

nothing to commit, working tree clean

C:\scripts\Python\Cyren>git push
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 454 bytes | 454.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/siggib007/python.git
e85489f..1240039 master -> master

C:\scripts\Python\Cyren>git log archive\CyrenDopplerAPI.py
commit 1240039a7e93993027f22979908ee4a9837a5474 (HEAD -> master, origin/master)
Author: Siggi@Reba <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="54273d33333d1427212431263331313f7a2127" rel="noreferrer noopener nofollow">[email protected]</a>>
Date: Sun May 8 22:49:03 2022 +0000

cleanup and archiving

git log 不显示移动之后的 more 之前的日志条目。我认为这意味着它已被删除。

顺便说一句,这是相应的 github 存储库的链接 https://github.com/siggib007/python/tree/master/Cyren

此外,这不是一个孤立的事件,这是我的控制台日志,重现了我之前多次注意到的问题。

最佳答案

使用git log --follow跟踪重命名。

--follow

Continue listing the history of a file beyond renames (works only for a single file).

您可以通过设置 log.follow 将其设置为默认值配置选项为true:

log.follow

If true, git log will act as if the --follow option was used when a single is given. This has the same limitations as --follow, i.e. it cannot be used to follow multiple files and does not work well on non-linear history.

要设置它运行:

$ git config --global log.follow true

关于git - 使用 git 移动文件时丢失历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72165668/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com