我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们
文章版本: Enterprise Server 2.16

此版本的 GitHub Enterprise 将停止服务 此版本的 GitHub Enterprise 已停止服务 2020-01-22. 即使针对重大安全问题,也不会发布补丁。 For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise. For help with the upgrade, contact GitHub Enterprise support.

Moving a file to a new location using the command line

You can use the command line to move files within a repository by removing the file from the old location and then adding it in the new location.

Many files can be moved directly on GitHub Enterprise, but some files, such as images, require that you move them from the command line.

This procedure assumes you've already:

  1. On your computer, move the file to a new location within the directory that was created locally on your computer when you cloned the repository.

  2. Open TerminalTerminalGit Bashthe terminal.

  3. Use git status to check the old and new file locations.

    $ git status
    > # On branch your-branch> # Changes not staged for commit:
    > #   (use "git add/rm ..." to update what will be committed)
    > #   (use "git checkout -- ..." to discard changes in working directory)
    > #
    > #     deleted:    /old-folder/image.png> #
    > # Untracked files:
    > #   (use "git add ..." to include in what will be committed)
    > #
    > #     /new-folder/image.png> #
    > # no changes added to commit (use "git add" and/or "git commit -a")
  4. 将要提交的文件暂存到本地仓库。 This will delete, or git rm, the file from the old location and add, or git add, the file to the new location.

    $ git add .
    # Adds the file to your local repository and stages it for commit. 要取消暂存文件,请使用 'git reset HEAD YOUR-FILE'。
  5. Use git status to check the changes staged for commit.

    $ git status
    > # On branch your-branch> # Changes to be committed:
    > #   (use "git reset HEAD ..." to unstage)
    > #
    > #    renamed:    /old-folder/image.png -> /new-folder/image.png
    # Displays the changes staged for commit
  6. 提交暂存在本地仓库中的文件。

    $ git commit -m "Move file to new directory"
    # Commits the tracked changes and prepares them to be pushed to a remote repository. 要删除此提交并修改文件,请使用 'git reset --soft HEAD~1' 并再次提交和添加文件。
  7. 在本地仓库中推送更改到 您的 GitHub Enterprise Server 实例。

    $ git push origin your-branch# 将本地仓库中的更改推送到指定为源的远程仓库

Further reading

问问别人

找不到要找的内容?

联系我们