What is the git command for the action to be considered at the remote repository after I deleted a tracked file?

huangapple go评论64阅读模式
英文:

What is the git command for the action to be considered at the remote repository after I deleted a tracked file?

问题

有一个已跟踪的文件,我们不再需要它了。我已经在我的本地仓库中删除了这个文件。所以在远程仓库上生效此操作的git命令是什么?

英文:

There is a tracked file that we do not need anymore. I deleted the file on my local repository. So what are the git commands to write in order for the action to be effective on the remote repository ?

答案1

得分: 1

取消跟踪文件

如果你不希望 git 跟踪某个文件,你可以使用以下命令取消跟踪:

git rm --cached 文件名

然后你需要本地提交这些更改:

git commit

之后,你可以将更改推送到远程仓库:

git push

删除文件

如果你想删除一个文件,只需将它从仓库中移除。

使用以下命令添加更改:

git add -A

你可以使用 git status 检查更改:

在分支 main 上
你的分支与 'origin/main' 一致。

要提交的更改:
  (使用 "git restore --staged <文件>..." 来取消暂存)
        删除:    file.md

然后,你可以提交你的更改:

git commit -m "删除了文件"

将更改推送到远程仓库:

git push
英文:

Untrack the file

If you don't want git to track a file you have to can untrack it with

git rm --cached filename

Then you will need to commit the changes locally with:

git commit

After that you can push the changes to the remote with:

git push

Delete the file

If you want to delete a file, simply remove it from the repo.

Add the changes with:

git add -A

You can check the changes with git status:

On branch main
Your branch is up to date with &#39;origin/main&#39;.

Changes to be committed:
  (use &quot;git restore --staged &lt;file&gt;...&quot; to unstage)
        deleted:    file.md


Then you can commit your changes with:

git commit -m &quot;Removed the file&quot;

To push the changes on the remote:

git push

huangapple
  • 本文由 发表于 2023年8月4日 23:40:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76837398.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定