English 中文(简体)
How to switch branches with git and get ignored files removed?
原标题:
  • 时间:2009-11-07 08:43:21
  •  标签:
  • git

Given I have a master branch and a other branch. In the other branch are files I don t want to commit (e.g. log files) so I ignored them in .gitignore.

When I switch to the master branch, these ignored files stay but they belong only to the other branch.

Is there a way to attach some ignored files to a specific branch (without committing them)?

最佳回答

It s not possible. If you tell git to ignore these files, git will ignore them, ie. it will not touch them no matter what git operation you are performing.

You could either use a branch-specific naming scheme for your log files or save them in a different directory for each branch.

Alternatively, you could write a hook script (post-checkout) that manages files in a separate git repository.

问题回答

Git intentionally makes it hard to lose data by accident. For example, what if there were source files that you forgot to git add? There is a git clean command to help you clean up your working copy. Passing the -x flag causes it to also remove files normally ignored by .gitignore. E.g.,

git clean -f -x

If you want more control, you can pass the --dry-run flag to get the list of files and then you could write some shell script to look for certain kinds of files (e.g., *.log).

Then, you could install this script as a post-checkout script (see git-hooks for examples).





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签