Git Flashcards
Add to .ignore
echo filename > .gitignore
Track multiple files
git add filename1 filename2
git add это
Кэширование файла.
Помещение файла в индекс.
What does git ls-files --stage
display?
Lists files in the Git index (staging area) along with their mode bits, object names (SHA-1 hashes), and stage numbers.
List a summary of commit authors, display only the top 3 contributors
git shortlog -sn | head -3
266 michael_soldatkin
245 Aleksandr
153 Alexandr Gubanov
Конвертировать файл из подготовленного в неподготовленный
git rm --cached filename
Отследить историю файла
git log --follow filename
Добавить неотслеживаемый локальный файл
.git/info/exclude
Игнорируем все .о файлы, но отследим один файл в подкаталоге
cat .gitignore *.o cd ./cache cat .gitignore !driver.o
Pickaxe: Показывает комиты, в которых добавляется или удаляется заданная строка с сокращенным сообщением и размером хэша в указанном файле.
git log -Sinclude --pretty=oneline --abbrev-commit init/version.c
Сделать ветку, указав начальную фиксацию
git branch my_branch dev_hot_fix
Переключиться на другую ветку и очистить рабочий каталог
git switch other-branch --discard-changes
Сделать новую фиксацию, находясь в Detached Head
git checkout -b new_branch
Удалить ветку
Force delete:
git branch -d bug/pr3 Force delete: git branch -D bug/pr3
Отмена слияния (восстановление рабочего каталога в состояние до слияния)
git reset --hard HEAD
Отменить слияние после успешного завершения слияния локально.
git reset --hard ORIG_HEAD
Вернуться к исходному состоянию конфликта слияния
git checkout -m
Отменить последнюю фиксацию
git reset HEAD^
Подробный пример отмены фиксации
git show-branch --more=5 [master] Add more foo. [master^] Add master_file. git reset HEAD^ git show-branch --more=5 [master] Add master_file.
Отмена (инверсия) последней фиксации
git revert HEAD
Revert the changes specified by the fourth last commit in HEAD
git revert HEAD~3
Revert the changes done by commits from the fifth last commit in master (included) to the third last commit in master (included)
git revert master~5..master~2
Apply and remove stash from the list
git stash pop
Name a stash
git stash push -m 'description'
deprecated:
~~~
git stash save ‘description’
~~~
Stash list
git stash list
View a summary of a stash
$ git stash show index.html | 1 + style.css | 3 +++ 2 files changed, 4 insertions(+)
View the full diff of a stash compared to the working directory
$ git stash show -p diff --git a/style.css b/style.css new file mode 100644 index 0000000..d92368b --- /dev/null \+++ b/style.css @@ -0,0 +1,3 @@
Delete a stash
$ git stash drop stash@{1} Dropped stash@{1} (17e2697fd8251df6163117cb3d58c1f62a5e7cdb)
Clear stash
git stash clear
Stash untracked files
git stash --include-untracked
To save a stash with a message
git stash push -m "my_stash_name"
To save the specific file to stash with a message
git stash push -m "my_stash_name" example.txt
To pop (i.e. apply and drop) the nth stash
git stash pop stash@{n}
Undo not pushed last commit and save local changes
git reset --soft HEAD~1
Show useful visual condensed git log with decorations (god)
git log --graph --oneline --decorate
What is merge fast forward?
When the feature branch is ahead of the main, merge commit would not be created. to prevent this behavior use --no-ff