代码之家  ›  专栏  ›  技术社区  ›  isignisign

Git移动我从未移动过的文件

git
  •  2
  • isignisign  · 技术社区  · 6 年前

    我想在git方面获得更多的经验,所以我决定自己做一些试验。

    我基本上想看看在移动/删除/编辑文件时合并和重新定位之间的不同行为。

    所以我创建了如下文件结构:

    ├── a
    │   ├a.txt
    │   ├aa.txt
    ├── b
    │   ├b.txt
    │   ├bb.txt
    ├── c
    │   ├c.txt
    │   ├cc.txt
    

    每本书的内容 .txt 然后我做了三根树枝

    MoveATXT
    DeleteATXT
    EditATXT
    

    a.txt 住在/a的 因为搬家我搬家了 /a/a.txt /b/a.txt 所有移动/删除都是通过git命令完成的 git rm git mv

    行为 git merge 是我所期待和理解的。 是的 git rebase 这让我很困惑。

    当我做了一个新的分支 BranchOne 我决定先 git rebase MoveATXT 一切进展顺利,这一举动出现了。接下来我决定 git rebase DeleteATXT 这就是我觉得奇怪的地方。

    它首先给了我一份打印出来的错误信息。这几乎是我所期望的。

    First, rewinding head to replay your work on top of it...
    Applying: Move a.txt to b/
    Using index info to reconstruct a base tree...
    A       a/a.txt
    Falling back to patching base and 3-way merge...
    CONFLICT (rename/delete): a/a.txt deleted in HEAD and renamed to b/a.txt in Move a.txt to b/. Version Move a.txt to b/ of b/a.txt left in tree.
    error: Failed to merge in the changes.
    Patch failed at 0001 Move a.txt to b/
    Use 'git am --show-current-patch' to see the failed patch
    
    Resolve all conflicts manually, mark them as resolved with
    "git add/rm <conflicted_files>", then run "git rebase --continue".
    You can instead skip this commit: run "git rebase --skip".
    To abort and get back to the state before "git rebase", run "git rebase --abort".
    

    git status

    $ git status
    rebase in progress; onto 7a2c06d
    You are currently rebasing branch 'test' on '7a2c06d'.
      (fix conflicts and then run "git rebase --continue")
      (use "git rebase --skip" to skip this patch)
      (use "git rebase --abort" to check out the original branch)
    
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            renamed:    a/aa.txt -> b/aa.txt
    
    Unmerged paths:
      (use "git reset HEAD <file>..." to unstage)
      (use "git add <file>..." to mark resolution)
    
            added by them:   b/a.txt
    

    它告诉我 a/aa.txt 已经转移到 b/aa.txt

    更进一步,当我 ls 它告诉我 a/ 不见了

    $ ls
    b/  c/
    

    b/ 两者都有 a、 文本 `aa.txt文件

    $ ls b/
    a.txt  aa.txt  b.txt  bb.txt
    

    a/aa.txt文件 一个/

    0 回复  |  直到 6 年前