简体   繁体   English

git track,ignore,delete,untrack

[英]git track, ignore, delete, untrack

I seem to have ballsed up my git repo by tracking a file, later ignoring it and then deleting it. 我似乎通过跟踪一个文件来摧毁我的git repo,后来忽略它然后删除它。 The thing is, I want the file to be present in a remote repository (the live site), but just don't want to track. 问题是,我希望文件存在于远程存储库(实时站点)中,但只是不想跟踪。

Now my master branch is trying to remove all the files from the repository, which I know will delete them on the remote branch when I push changes... I just want to untrack them, but cannot do that as they're already deleted on master and git rm -r --cached says 'did not match any files'. 现在我的主分支正在尝试从存储库中删除所有文件,我知道当我推送更改时,它会在远程分支上删除它们...我只想解开它们,但不能这样做,因为它们已经被删除了master和git rm -r --cached说“与任何文件都不匹配”。

How can I untrack these deleted files without removing them from the remote repository? 如何在不从远程存储库中删除这些已删除文件的情况下将其删除?

You just don't want to track a file, but you want to keep the file in the remote repository (non-bare). 您只是不想跟踪文件,但是您希望将文件保留在远程存储库中(非裸)。

Use this git command. 使用这个git命令。 After you do this, git stops checking the file for possible modifications. 执行此操作后,git停止检查文件以进行可能的修改。

git update-index --assume-unchanged  <filename>

At any time, you can track again by setting --no-assume-unchaged flag 您可以随时通过设置--no-assume-unchaged标志再次跟踪

git update-index --no-assume-unchanged  <filename>

These command do not affect the remote repository. 这些命令不会影响远程存储库。

For more information: http://kar-git.blogspot.in/2012/11/how-to-set-git-to-ignore-few-files-like.html 有关更多信息,请访问: http//kar-git.blogspot.in/2012/11/how-to-set-git-to-ignore-few-files-like.html

git rm is used to delete files from the repository. git rm用于从存储库中删除文件。

To stop tracking them, you can, after deleting, add them to the .gitignore file in the root of the repository. 要停止跟踪它们,您可以在删除后将它们添加到存储库根目录中的.gitignore文件中。

Even if you have untracked a file with git rm, you can still checkout a previous version of that file, eg 即使您没有使用git rm解压缩文件,您仍然可以签出该文件的先前版本,例如

In your local repo: git rm foo git commit -m 'removed foo' git push origin master 在你的本地回购:git rm foo git commit -m'删除了foo'git push origin master

In the remote repository: 在远程存储库中:

git pull origin master // foo will be removed
git checkout abcd1234 -- foo // checkout foo from commit abcd1234 (foo is staged)
git reset HEAD // unstage foo
git status

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       foo

Then add to .gitignore to untrack 然后添加到.gitignore以进行跟踪

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM