Вступление
Это не Java, но несколько новичков-разработчиков задают один и тот же вопрос, как использовать GIT и как GIT работает, так что вот так …
Вы когда-нибудь работали в SVN? Ну забудь все что знаешь и давай начнем сначала
Что такое GIT-репо?
В общем, есть два зеркальных репо. Ваш локальный репо и удаленный репо. Да, два РЕПО. У каждого в команде есть действительная копия всего репо, поэтому даже если ваш удаленный сервер умрет, вы можете настроить его снова и просто перенести (спойлер) ваше репо на сервер репозитариев.
Ваш локальный репозиторий состоит из трех «деревьев», поддерживаемых git:
- Рабочий каталог, который содержит актуальные файлы.
- Индекс, который действует как постановка
- ГОЛОВКА, которая указывает на последний сделанный вами коммит.

Итак, давайте начнем ускоренный курс …
Создать новый репозиторий git.
|
1
2
|
#Start a git repository in the particular pathgit init |
оформить репозиторий
|
1
2
3
4
5
|
#Create a working copy of a local repository by running the commandgit clone /path/to/repository#When using a remote server, your command will begit clone [email protected]:/path/to/repository |
Добавить и зафиксировать
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#Shows current branch status and lists files that have changes.#First it lists files in the Stage (to be committed)#And below go the files that are not staged.git status#You can propose changes (add it to the Index) usinggit add#Or if you want to add everythinggit add .#Or evengit add --all#To actually commit these changes usegit commit -m "An awesome commit message :p"#If a file was added to the stage by mistake undo a stagegit reset particularFile.extension#Reseting code by deleting all changes. HEAD is the latest local commitgit reset --hard HEAD#Same as above but N commits back.git reset --hard HEAD~N#Reset code but keep changes locally. (usefull for uncommiting a not pushed mistake)#Use HEAD~2 if a merge occured.git reset --soft HEAD~1#Save local uncommitted changes temporarilygit stash#Bring saved changes backgit stash apply |
Проверьте, что случилось, пока вас не было …
|
1
2
3
4
5
|
#Use to see changes committed. Commit it can be found by git loggit show --pretty="" --name-only [commitID]Pushing changes#Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository in your desired branch, executegit push origin Branching |
Обновление и слияние
|
1
2
|
#You can study repository history using and get commit id if neededgit log |
Как обнаружить ошибку с помощью git bisect
Эта вещь сломана! Это сработало на прошлой неделе! Что произошло? Можем ли мы точно указать код, который его сломал!
Да, у всех нас был этот разговор в прошлом … Предполагая, что у нас есть сообщения Good Commit (это еще одна тема сообщения, но давайте продолжим), мы будем использовать git bisect.
Вы предоставляете git bisect две точки, ХОРОШИЙ момент времени и ПЛОХОЙ момент времени. Предположим, что это коммиты HEAD и 134245634bkl2730bc5der. Это делит время на части и дает вам коммит между ними. Если код в порядке, вы помечаете его как ХОРОШО, иначе вы помечаете его как ПЛОХОЙ. После нескольких итераций вы попадаете на коммит, который вызвал проблему. Проверьте пример ниже
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
git bisect start HEAD 134245634bkl2730bc5derBisecting: 4 revisions left to test after this (roughly 2 steps)[3453lj45b3ljhrgo2ug42bbh98112] Revert "Refactored hello() method to pass sonar"#test your code heregit bisect bad #or use a script that exits 1Bisecting: 2 revisions left to test after this (roughly 1 step)[x7y435h34r87yhndfdsf0dsfw3452] Added some nice staff I found on the webgit bisect good #or use a script that exits 0Bisecting: 0 revisions left to test after this (roughly 0 steps)[234fy435h45b09jdfdsf0dsfw3452] Added ability to fly like supermangit bisect bad234fy435h45b09jdfdsf0dsfw3452is the first bad commitcommit 234fy435h45b09jdfdsf0dsfw3452Author: Alexius [email protected]Date: Sat Oct 12 15:40:46 2019Added ability to fly like supermanbisect run success |
Это вся необходимая информация о GIT!
Наслаждайтесь!
|
Смотрите оригинальную статью здесь: Ускоренный курс Git Essentials Мнения, высказанные участниками Java Code Geeks, являются их собственными. |