Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   gitfaq    ( 7 )

Часто задаваемые вопросы об использовании Git (Frequently asked questions about using Git)

COMMON ISSUES

I've made a mistake in the last commit. How do I change it?
           You can make the appropriate change to your working tree, run
           git add <file> or git rm <file>, as appropriate, to stage it,
           and then git commit --amend. Your change will be included in
           the commit, and you'll be prompted to edit the commit message
           again; if you wish to use the original message verbatim, you
           can use the --no-edit option to git commit in addition, or
           just save and quit when your editor opens.

I've made a change with a bug and it's been included in the main branch. How should I undo it? The usual way to deal with this is to use git revert. This preserves the history that the original change was made and was a valuable contribution, but also introduces a new commit that undoes those changes because the original had a problem. The commit message of the revert indicates the commit which was reverted and is usually edited to include an explanation as to why the revert was made.

How do I ignore changes to a tracked file? Git doesn't provide a way to do this. The reason is that if Git needs to overwrite this file, such as during a checkout, it doesn't know whether the changes to the file are precious and should be kept, or whether they are irrelevant and can safely be destroyed. Therefore, it has to take the safe route and always preserve them.

It's tempting to try to use certain features of git update-index, namely the assume-unchanged and skip-worktree bits, but these don't work properly for this purpose and shouldn't be used this way.

If your goal is to modify a configuration file, it can often be helpful to have a file checked into the repository which is a template or set of defaults which can then be copied alongside and modified as appropriate. This second, modified file is usually ignored to prevent accidentally committing it.

I asked Git to ignore various files, yet they are still tracked A gitignore file ensures that certain file(s) which are not tracked by Git remain untracked. However, sometimes particular file(s) may have been tracked before adding them into the .gitignore, hence they still remain tracked. To untrack and ignore files/patterns, use git rm --cached <file/pattern> and add a pattern to .gitignore that matches the <file>. See gitignore(5) for details.

How do I know if I want to do a fetch or a pull? A fetch stores a copy of the latest changes from the remote repository, without modifying the working tree or current branch. You can then at your leisure inspect, merge, rebase on top of, or ignore the upstream changes. A pull consists of a fetch followed immediately by either a merge or rebase. See git-pull(1).