Редактирование: Участник:Lit-uriy/GitIntroductionWithQt
Материал из Wiki.crossplatform.ru
Внимание: Вы не представились системе. Ваш IP-адрес будет записан в историю изменений этой страницы.
Правка может быть отменена. Пожалуйста, просмотрите сравнение версий, чтобы убедиться, что это именно те изменения, которые вас интересуют, и нажмите «Записать страницу», чтобы изменения вступили в силу.
Текущая версия | Ваш текст | ||
Строка 113: | Строка 113: | ||
==== Реальное внесение изменений ==== | ==== Реальное внесение изменений ==== | ||
- | + | Now we can go ahead and start making changes: | |
{{code|bash|code=$ edit src/corelib/tools/qstring.cpp}} | {{code|bash|code=$ edit src/corelib/tools/qstring.cpp}} | ||
- | + | The diff command shows us what we have changed: | |
{{code|bash|code=$ git diff | {{code|bash|code=$ git diff | ||
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp | diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp | ||
Строка 157: | Строка 157: | ||
int lastIndexOf(const QRegExp &, int from = -1) const;}} | int lastIndexOf(const QRegExp &, int from = -1) const;}} | ||
- | + | The status command gives an overview of what “git commit” would do: | |
{{code|bash|code=$ git status | {{code|bash|code=$ git status | ||
# On branch master | # On branch master | ||
Строка 169: | Строка 169: | ||
no changes added to commit (use "git add" and/or "git commit -a")}} | no changes added to commit (use "git add" and/or "git commit -a")}} | ||
- | + | Following the recommendation in the output we mark qstring.cpp and .h as files to be included in the next commit: | |
{{code|bash|code=$ git add src/corelib/tools/qstring.cpp src/corelib/tools/qstring.h | {{code|bash|code=$ git add src/corelib/tools/qstring.cpp src/corelib/tools/qstring.h | ||
$ git status | $ git status | ||
Строка 181: | Строка 181: | ||
# Untracked files not listed (use -u option to show untracked files)}} | # Untracked files not listed (use -u option to show untracked files)}} | ||
- | + | And finally we create a new commit: | |
{{code|bash|code=$ git commit -m "Add a new reversed() function to QString" | {{code|bash|code=$ git commit -m "Add a new reversed() function to QString" | ||
[my-feature c8d9c54] Add a new reversed() function to QString}} | [my-feature c8d9c54] Add a new reversed() function to QString}} | ||
- | Обычно git откроет новый текстовый редактор, если вы пропускаете | + | Обычно git откроет новый текстовый редактор, если вы пропускаете параметр ''-m''. |
- | + | Marking files to be included in commits means adding them to git’s staging area. The staging area is a powerful concept, making it easy to work on multiple files simultaenously while still creating small incremental commits. | |
- | === | + | === Common operations and fixing mistakes === |
- | + | This section gives recipes for fixing common mistakes and explains common operations such as reviewing your changes before committing using the diff command. | |
- | + | You can undo changes to a file before it is committed with the checkout command: | |
{{Команда|$ git checkout HEAD -- src/corelib/tools/qstring.cpp}} | {{Команда|$ git checkout HEAD -- src/corelib/tools/qstring.cpp}} | ||
- | + | If you have accidentially marked a file for the next commit you can reset it like this: | |
{{Команда|$ git reset HEAD -- src/corelib/tools/qstring.cpp}} | {{Команда|$ git reset HEAD -- src/corelib/tools/qstring.cpp}} | ||
- | + | This will exclude the file from the next commit and leave it in your working directory unchanged with your modifications intact. | |
- | + | After changing a file the git diff command shows the lines you have modified. The difference is calculated from the file in your working directory and the file when it was added to the staging area using git add. | |
- | + | If you want to show the difference between the file in the staging area and the last commit you have to pass an option to the diff command: | |
{{Команда|$ git diff --cached}} | {{Команда|$ git diff --cached}} | ||
- | + | The diff command optionally takes directories and files as argument, to limit the output. | |
- | + | Files are renamed in git by renaming them in your working directory using a command/tool of your choice. Once you've renamed a file you have to tell git: | |
- | {{Команда| | + | {{Команда|[ rename oldfile.cpp to newfile.cpp using a graphical file manager ] |
$ git rm oldfile.cpp | $ git rm oldfile.cpp | ||
$ git add newfile.cpp}} | $ git add newfile.cpp}} | ||
- | + | Alternatively you can use the convenience mv command: | |
{{Команда|$ git mv oldfile.cpp newfile.cpp}} | {{Команда|$ git mv oldfile.cpp newfile.cpp}} | ||
- | + | One of git’s strengths is that it does not care how exactly you change your files. It is optimized to find out what changed after the fact. For example when copying a file in your source code it is enough to simply run “git add” with the new file. Git automatically finds out where the file was copied from. | |
=== Отправка и обновление ваших изменений === | === Отправка и обновление ваших изменений === | ||
==== Получение обновлений ==== | ==== Получение обновлений ==== | ||
- | + | After studying the previous chapters you should be able to develop small changes by creating commits in your local branches. This chapter guides you through the steps of combining your changes with the latest changes from the upstream repository and explains how to create separate patch files for submission into the project. | |
- | + | While developing code in your local clone of the project, the original repository evolves and sees new changes. First we update our mirror of the commits in the original repository using the fetch command: | |
{{Команда|$ git fetch | {{Команда|$ git fetch | ||
remote: Counting objects: 3013, done. | remote: Counting objects: 3013, done. | ||
Строка 231: | Строка 231: | ||
be7384d..822114e master -> origin/master}} | be7384d..822114e master -> origin/master}} | ||
- | + | The output indicates that the “master” branch in the original gitorious.org repository has been updated with new commits and these commits are now available in the locally mirrored origin/master branch. | |
- | + | You can inspect the new changes using the log or show commands: | |
{{Команда|$ git log -p origin/master}} | {{Команда|$ git log -p origin/master}} | ||
- | + | The log command will include the diffs of the individual commits if you specify the -p argument. | |
Updating your branch with the downloaded, new changes | Updating your branch with the downloaded, new changes | ||