Git Sürüm Kontrolüne Giriş
Önemli
A more in-depth guide on Git is available on the Git website.
Git, Linus Torvalds tarafından oluşturulan ve Linux çekirdeğini oluşturmak ve sürdürmekle de bilinen bir Dağıtılmış Sürüm Kontrol Sistemidir (VCS). Sürüm Kontrolü, geliştiriciler için kod değişikliklerini izlemek için bir sistemdir. Git Sürüm Kontrolünün avantajları şunlardır:
Separation of testing environments into branches
Geçmişi silmeden belirli bir işlemeye gitme yeteneği
Taahhütleri çeşitli şekillerde, bunları birleştirmek de dahil olmak üzere yönetme yeteneği
Çeşitli diğer özellikler, bkz. here
Önkoşullar
Önemli
Bu eğitici Windows işletim sistemini kullanır
Git’i aşağıdaki bağlantılardan indirip kurmanız gerekir:
Windows <https://git-scm.com/download/win> _
macOS <https://git-scm.com/download/mac> _
Linux <https://git-scm.com/download/linux> _
Not
https://www.google.com/search?q=adding+git+to+path yolunuza Git eklemeniz gerekebilir
Git Kelime Bilgisi
Git revolves around several core data structures and commands:
Repository: Kök dizindeki “.git ‘’ klasörü dahil kodunuzun veri yapısı
Commit: a particular saved state of the repository, which includes all files and additions
Branch: a means of grouping a set of commits. Each branch has a unique history. This is primarily used for separating development and stable branches.
Push: uzak depoyu yerel değişikliklerinizle güncelleyin
Pull: Yerel deponuzu uzaktan değişikliklerle güncelleyin
Clone: retrieve a local copy of a repository to modify
Fork: duplicate a pre-existing repository to modify, and to compare against the original
Merge: combine various changes from different branches/commits/forks into a single history
Depo
Git deposu, bir projenin yapısını, geçmişini ve dosyalarını içeren bir veri yapısıdır.
Git depoları genellikle şunlardan oluşur:
Bir
.git
klasörü. Bu klasör arşivle ilgili çeşitli bilgileri içerir.Bir
.gitignore
dosyası. Bu dosya, kaydettiğinizde dahil edilmesini istemediğiniz dosyaları veya dizinleri içerir.Dosyalar ve Klasörler. Bu, deponun ana içeriğidir.
Depoyu oluşturma
You can store the repository locally, or through a remote – a remote being the cloud, or possibly another storage medium or server that hosts your repository. GitHub is a popular free hosting service. Numerous developers use it, and that’s what this tutorial will use.
Not
There are various providers that can host repositories. Gitlab and Bitbucket are a few alternatives to Github.
GitHub Hesabı Oluşturma
Go ahead and create a GitHub account by visiting the website and following the on-screen prompts.
Yerel Yaratılış
Hesabınızı oluşturup doğruladıktan sonra ana sayfayı ziyaret etmek isteyeceksiniz. Gösterilen resme benzer görünecek.
Sağ üstteki artı simgesini tıklayın.
Sonra “Yeni Depo” tıklayın
Uygun bilgileri doldurun ve ardından “Depo oluştur” u tıklayın
Buna benzer bir ekran görmelisiniz
Not
The keyboard shortcut Ctrl+~ can be used to open a terminal in Visual Studio Code for Windows.
Şimdi bir PowerShell penceresi açıp proje dizininize gitmek isteyeceksiniz. PowerShell ile ilgili mükemmel bir öğretici burada <https://programminghistorian.org/en/lessons/intro-to-powershell> __ bulunabilir. Lütfen alternatif işletim sistemlerinde bir terminalin nasıl açılacağını öğrenmek için arama motorunuza danışın.
If a directory is empty, a file needs to be created in order for git to have something to track. In the below Empty Directory example, we created a file called README.md
with the contents of # Example Repo
. For FRC® Robot projects, the below Existing Project commands should be run in the root of a project created by the VS Code WPILib Project Creator. More details on the various commands can be found in the subsequent sections.
Not
Dosya yolunu değiştirin Replace the filepath "C:\Users\ExampleUser9007\Documents\Example Folder"
repo’yu oluşturmak istediğiniz klasörle ve uzak URL’yi değiştirin. Önceki adımlarda oluşturduğunuz deponun URL’si ile``https://github.com/ExampleUser9007/ExampleRepo.git``.
> cd "C:\Users\ExampleUser9007\Documents\Example Folder"
> git init
Initialized empty Git repository in C:/Users/ExampleUser9007/Documents/Example Folder/.git/
> echo "# ExampleRepo" >> README.md
> git add README.md
> git commit -m "First commit"
[main (root-commit) fafafa] First commit
1 file changed, 1 insertions(+), 0 deletions(-)
create mode 100644 README.md
> git remote add origin https://github.com/ExampleUser9007/ExampleRepo.git
> git push -u origin main
> cd "C:\Users\ExampleUser9007\Documents\Example Folder"
> git init
Initialized empty Git repository in C:/Users/ExampleUser9007/Documents/Example Folder/.git/
> git add .
> git commit -m "First commit"
[main (root-commit) fafafa] First commit
1 file changed, 1 insertions(+), 0 deletions(-)
create mode 100644 README.md
> git remote add origin https://github.com/ExampleUser9007/ExampleRepo.git
> git push -u origin main
Kaydetme
Depolar, öncelikle kayıtlardan oluşur. İşlemler, kaydedilmiş durumlar veya kodun sürümleridir.
Önceki örnekte, README.md adlı bir dosya oluşturduk. Bu dosyayı favori metin düzenleyicinizde açın ve birkaç satırı düzenleyin. Dosyayı biraz düzelttikten sonra kaydedip kapatın. PowerShell’e gidin ve aşağıdaki komutları yazın.
> git add README.md
> git commit -m "Adds a description to the repository"
[main bcbcbc] Adds a description to the repository
1 file changed, 2 insertions(+), 0 deletions(-)
> git push
Not
Writing good commit messages is a key part of a maintainable project. A guide on writing commit messages can be found here.
Git Çekme
Not
Kullanıcı otomatik olarak mevcut çalışma dalıyla birleşmek istemediğinde git fetch
kullanılabilir
Bu komut, uzak depodan geçmişi veya taahhütleri alır. Uzaktan kumanda, sahip olmadığınız işleri içerdiğinde, otomatik olarak birleştirmeye çalışacaktır. Bakınız: ref:docs / yazılım / temel-programlama / git-başlarken: Birleştirme.
Çalıştır: git pull
Git Ekle
This command “stages” the specified file(s) so that they will be included in the next commit.
For a single file, run git add FILENAME.txt
where FILENAME.txt is the name and extension of the file to add.
To add every file/folder that isn’t excluded via gitignore,
run git add .
. When run in the root of the repository this command will stage every untracked, unexcluded file.
Git Kaydetme
This command creates the commit and stores it locally. This saves the state and adds it to the repository’s history. The commit will consist of whatever changes (“diffs”) were made to the staged files since the last commit. It is required to specify a “commit message” explaining why you changed this set of files or what the change accomplishes.
Çalıştır: git commit -m "mesajı buraya yazın"
Git Push
Yerel değişikliklerinizi uzak bilgisayara (Bulut) yükleyin (itin)
Çalıştır: git push
Şubeler
Branches in Git are similar to parallel worlds. They start off the same, and then they can “branch” out into different varying paths. Consider the Git control flow to look similar to this.
Yukarıdaki örnekte, FeatureB, FeatureA ile birleştirilmiştir. Bu, birleştirme denen şeydir. Değişiklikleri bir daldan diğerine “birleştiriyorsunuz”.
Şube Oluşturma
Çalıştır: git şube şube adı
burada şube adı, oluşturulacak dalın adıdır. Yeni şube geçmişi, mevcut aktif şubeden oluşturulacaktır.
Şube Girmek
Bir şube oluşturulduktan sonra şubeye girmeniz gerekir.
Çalıştır: git checkout şube adı
burada şube adı, daha önce oluşturulan daldır.
Birleştirme
In scenarios where you want to copy one branches history into another, you can merge them. A merge is done by calling git merge branch-name
with branch-name being the name of the branch to merge from. It is automatically merged into the current active branch.
It’s common for a remote repository to contain work (history) that you do not have. Whenever you run git pull
, it will attempt to automatically merge those commits into your local copy. That merge may look like the below.
However, in the above example, what if File A was modified by both branch Feature1 and Feature2? This is called a merge conflict. A merge conflict can be resolved by editing the conflicting file. In the example, we would need to edit File A to keep the history or changes that we want. After that has been done, simply re-add, re-commit, and then push your changes.
Sıfırlama
Bazen geçmişin sıfırlanması veya bir işlemenin geri alınması gerekir. Bu, birden çok şekilde yapılabilir.
Kaydetmeyi Geri Döndürme
Not
Git, hangi şubeyi veya menşei seçmesi gerektiğini bilmediği için bir birleştirmeyi geri alamazsınız.
Geçmişi geri döndürmek için bir commit çalıştırmasına yol açan git revert commit-id
. Commit ID’leri git log
komutu kullanılarak gösterilebilir.
Kafayı Sıfırlama
Uyarı
Kafayı zorla sıfırlamak tehlikeli bir komuttur. Hedefin dışındaki tüm geçmişi kalıcı olarak siler. Uyarıldın!
Çalıştır: git reset --hard commit-id
.
Çatallar
Çatallar dallara benzer şekilde tedavi edilebilir. Yukarı akışı (orijinal depo) orijinle (çatallı depo) birleştirebilirsiniz.
Bir Depoyu Klonlamak
Bir deponun zaten bir uzaktan kumandada yaratılmış ve depolanmış olması durumunda, onu kullanarak klonlayabilirsiniz.
git clone https://github.com/myrepo.git
where myrepo.git
is replaced with your git repo. If you follow this, you can skip to commits.
Çatal Güncelleme
Yukarı akışı ekleyin:
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
Eklendiğini onaylayın:
git remote -v
Yukarı akıştan değişiklikleri çekin:
git yukarı akış getir
Değişiklikleri başlıkta birleştirin:
git merge upstream / upstream-branch-name
Gitignore
Önemli
Ekiplerin, robot projelerinde bulunan “.gitignore ‘’ dosyasını değiştirmemeleri son derece önemlidir. Bu, çevrimdışı dağıtımın çalışmamasına neden olabilir.
Bir .gitignore
dosyası, genellikle git add
ile otomatik olarak işlenmeyecek dosyaların listesi olarak kullanılır. Bu dosyada listelenen herhangi bir dosya veya dizin işlenmeyecektir. Ayrıca git status <https://git-scm.com/docs/git-status> _ ile görünmeyecekler.
Additional Information can be found here.
Bir Klasörü Gizleme
Sonunda eğik çizgi ile gizlenecek klasörü içeren yeni bir satır eklemeniz yeterlidir
EX: `` dışlanacak dizin /``
Bir Dosyayı Gizlemek
Deponun köküne göre ön bekleyen dizinler de dahil olmak üzere, gizlenecek dosyanın adını içeren yeni bir satır ekleyin.
EX: dizin / dosyadan-gizlenecek.txt
EX: dosya-to-hide2.txt
ek bilgi
Resmi git <https://git-scm.com/docs/gittutorial> __ web sitesinde çok daha ayrıntılı bir eğitim bulunabilir.
Yaygın hataları düzeltmek için bir kılavuz, git uçuş kuralları havuzunda bulunabilir.