【问题标题】:How do I remove/add a file to stage that is deleted/untracked due to renaming folder如何删除/添加由于重命名文件夹而被删除/未跟踪的阶段的文件
【发布时间】:2020-02-02 10:58:20
【问题描述】:

用例

  • 使用fs.copyFile 通过遍历文件夹所具有的文件路径来复制文件夹及其文件。
  • 删除使用fs.unlinkSync复制的文件夹中的文件
  • 使用git.remove从git索引中删除现在删除的文件
  • 使用git.add 将复制的文件添加到暂存中并提交。

当前状态

  • 使用git status时显示已删除文件,标记为已删除。
  • 复制的文件也显示为未跟踪
fs.copyFile(oldPath, newPath, async err => {
  if (err) 
    return console.log(err)

  // Delete the old file
  await fs.unlinkSync(oldPath)
  // Remove the old file from git index
  await git.remove({
    dir,
    filepath: path.basename(oldPath)
  }).catch(error => console.log(error))
})

问题

  • 由于现在有已删除和未跟踪的同名文件,因此将刚刚的文件名传递给 filepath 将不起作用(猜测),因为现在有两个同名文件。

预期的解决方案

  • 使用git mv 命令时,它会从索引中删除已删除的文件并将复制的文件添加到暂存中,如何使用 isomorphic-git 复制此功能

【问题讨论】:

    标签: node.js git rename stage isomorphic-git


    【解决方案1】:

    解决方案是将相对路径传递给文件路径字段,以便从存储库目录到文件的相对路径

    await git.remove({
        dir,
        filepath: relativePath
      }).catch(error => console.log(error))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-01
      • 2014-07-02
      • 2018-07-21
      • 2016-02-27
      • 2014-08-09
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      相关资源
      最近更新 更多