git etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
git etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

3 Ocak 2023 Salı

git worktree seçeneği

Giriş
 git worktree seçeneği bizi IntelliJ ile sürekli branch değiştirmekten kurtarıyor. Çünkü bazen IntelliJ  sürekli bir şeyleri indekslediği için çalışmak zor oluyor

Örnek
Şöyle yaparız
# Add a new worktree
git worktree add ../new-dir existing-branch

# Remove a worktree
git worktree remove ../new-di


22 Aralık 2022 Perşembe

git diff seçeneği - Show Changes Not Yet Staged

Giriş
Açıklaması şöyle
Show Changes Not Yet Staged
Örnek
Açıklaması şöyle
If you face a situation where you need to share some changes in the code base that you have made with your co-worker but you cannot yet push your changes to the remote repository, you can use the patch command of git. Here is how it works:

After you have made all the changes you can run the following command:

git diff > filename.patch

git diff > filename.patch will create a file that will contain all uncommitted the changes you have made so far in the code base. Then you can simple share this file with your coworker via slack,email,USB etc .

You coworker will simply download you patch file and run the following command:

git apply filename.patch

This would apply all the code changes you have made in the code base on your coworker’s copy of the code.

Örnek
branch ve master arasındaki farkı görmek için şöyle yaparız.
git diff featureXYZ_branch master
Örnek
Şöyle yaparız.
git diff remotes/origin/featureXYZ_branch remotes/origin/master

1 Aralık 2022 Perşembe

git show seçeneği - Bir Commit Hakkında Bilgi Verir

Giriş
Açıklaması şöyle
git show can show you a high-level view of changes in a commit, but it also lets you see changes to specific files.
Değişen Dosya Hakkında Bilgi almak için şöyle yaparız
git show <commit> -- <filepath>
--stat seçeneği
Özet bilgi verir
Örnek
Şöyle yaparız
git show <commit> --stat




9 Kasım 2022 Çarşamba

git diff-tree seçeneği - Bir Commit'teki Değişen Dosyaları Gösterir

Giriş
Açıklaması şöyle
Q :How will you find a list of files that has been modified in a particular commit?
A : The command to get a list of files that has been changed in a particular commit is:
git diff-tree –r {commit hash}

-r flag allows the command to list individual files
commit hash lists all the files that were changed or added in the commit.

git revert seçeneği - Undo İçindir

Giriş
Söz dizimi şöyle
git revert <commit>
Açıklaması şöyle
Creates a new commit to revert the specified commit
Eğer commit belirtilmezse Head'den bir önceki sürümü alarak yeniden commitler.  Açıklaması şöyle
Creates a new commit to revert the specified commit
Undo için iki seçenek var. Açıklaması şöyle
There are two processes through which you can revert a commit:
1. Remove or fix the bad file in a new commit and push it to the remote repository. Then commit it to the remote repository using:
git commit –m “commit message”
2. Create a new commit to undo all the changes that were made in the bad commit. Use the following command:
git revert <commit id>
Yani 
1. Ya dosyayı değiştirip tekrar commit'leyeğiz, 
2. Ya da dosyayı bir önceki haline getirip, değiştirip tekrar commit'leyeğiz

Örnek
Elimizde şu sürüm olsun.
a -> b -> c -> d(HEAD)
Şöyle yaparız
git revert HEAD
Elimizde şu geçer. Bir önceki sürümde bulunan e harfi geri gelir. Şimdi bu dosyayı tekrar commit'lemek gerekir.
a -> b-> c -> d -> e(HEAD)


31 Ekim 2022 Pazartesi

git restore seçeneği

Giriş
Git 2.23 ile geliyor. git checkout iki tane işi birden yapıyor
1. Switch branches veya
2. Restore working tree files

Bu işleri iki farklı seçeneği böldüler
Örnek
Şöyle yaparız
git restore README.md
# same as 'git checkout -- README.md'
git restore --staged README.md
# same as 'git reset HEAD README.md'

git switch seçeneği

Giriş
Git 2.23 ile geliyor. git checkout iki tane işi birden yapıyor
1. Switch branches veya
2. Restore working tree files

Bu işleri iki farklı seçeneği böldüler

Örnek
Şöyle yaparız
git switch develop
# same as 'git checkout develop'

git switch -c new-branch
# same as 'git checkout -b new-branch'

15 Eylül 2022 Perşembe

git shortlog seçeneği

Örnek 
Top contributor kişiyi görmek için şöyle yaparız
> git shortlog -s -n
  830  Ali ...
  506  Ayşe ...
  460  Hakan ...

git remote seçeneği

Giriş
Açıklaması şöyle.
origin refers to the source repository from where it was cloned.
add
git remote add yazısına taşıdım

rename - rename remote repository
Örnek
Şöyle yaparız
$ git remote rename <old_name> <new_name>
set-url - change the address of a remote
Örnek
Şöyle yaparız
$ git remote set-url <name> <new_url>
remove seçeneği
Örnek
Şöyle yaparız
git remote remove origin
show seçeneği
Örnek
Şöyle yaparız
git remote show origin
-v seçeneği
Örnek
Şöyle yaparız
$ git remote -v
ocolak	git@github.com:orcunc/hazelcast.git (fetch)
ocolak	git@github.com:orcunc/hazelcast.git (push)


git reset seçeneği - Staging Area İçin Undo

Giriş
Şeklen şöyle


Şu anki branch'in daha önceki hallerinden birisine geri gelmek içindir. Açıklaması şöyle
git reset —mixed is used to undo changes made in the working directory and staging area.
git merge —abort helps stop the merge process and return back to the state before the merging began.
head seçeneği
-- file veya ~N seçeneği ile kullanılır

Örnek
Commit'lenmiş bir dosyayı silmek için şöyle yaparız.
$ git reset HEAD -- <file>
Örnek
Açıklaması şöyle
It also very common to accidentally push a few changes/files that were not supposed to be committed. Let’s say you had some config files or credentials files like AWS secrets or .pem files. These should not be pushed in the repository. One thing that many people might try in order to remove the pushed .pem from the remote repo is following:

Pull the latest code from the repo.
Delete the .pem file
Create another commit with the deleted .pem file
Push the changes back to remote repo
However in the above approach we haven’t completely removed the .pem from git. You see git keeps a track of all the files that you commit. So anyone can dig into the history of git commits and access the .pem file.

But git allows you to actually modify history. So the solution would be to move back to your safe commit and force push.

git reset HEAD~n is a command that lets you move back to your previous n commits. So git reset HEAD~2 will take you back two commits and will show you the changes of the last two commits.

git reset HEAD --hard will clean all those changes. So for example lets say you have the following commits


Now let’s say you want to remove the last two commits i.e (commit ‘Add aws secrets’ and ‘Add .pem file’)

First you will go back two commits by running the following command:

git reset HEAD~2

Now you can remove those two commits by using the following command:

git reset HEAD -- hard

Now for push the code to remote and your .pem files will be deleted from history as well.

--hard seçeneği
Örnek
Commitlenmiş her şeyi silmek için şöyle yaparız.
git reset --hard HEAD
Örnek - undo commit
Şöyle yaparız
$ git reset HEAD~ //Bir önceki commite gel
$ nano <file> //Dosyayı düzelt
$ git add <file> //Dosyayı tekrar ekle
$ git commit -c ORIG_HEAD //Commitle

git --version seçeneği

Giriş
git sürümünü gösterir

Örnek
Şöyle yaparız
> git --version
git version 2.33.0.windows.2


7 Eylül 2022 Çarşamba

git fetch seçeneği

Giriş
Bu komut ile remote repository'deki değişiklikler bizim repository'e getirilir ama çakışma varsa merge edilmez

Örnek
Şöyle yaparız
git fetch origin

22 Ağustos 2022 Pazartesi

git stash seçeneği

Giriş
Açıklaması şöyle
git stash : Değişiklikleri rafa kaldırır ve saklar
git stash apply : Rafa kaldırılan değişiklikleri yeniden uygular
push seçeneği
Add tracked files to stash

push -u
Add tracked and untracked files to stash and perform git clean

push -a
Add tracked, untracked, and ignored files to stash and perform git clean

git stash list
View all stashed data

git stash list -p
View all stashed data with changes

git stash show -p <stashIndex>
View specific stashed data

git stash clear
Delete all stashes

git stash drop <stashIndex>
Delete a specific stash

git stash apply <stashIndex>
Apply a stash into the workspace

git stash pop <stashIndex>
Apply the topmost stash and delete it

git stash branch <branchName> <stashIndex>
Apply stash into a separate branch




8 Mart 2022 Salı

git clone seçeneği - Belirtilen URL'yi Getirir

Giriş
Uzak depodaki projeyi yerel depoya kopyalamak için  kullanılır. Remote Repository iki branch'ten oluşuyor olabilir. Master ve develop.

Not : svn'den gelenler için bu komut kafa karıştırıcı çünkü svn'deki checkout komutuna denk geliyor.

Örnek
Şöyle yaparız
git clone https://github/com/something
Örnek
Bulunduğumuz dizine clone yapmak istersek şöyle yaparız.
git clone git@github.com:whatever .
Belli bir dizine clone yapmak istersek şöyle yaparız.
git clone git@github.com:whatever folder-name
--depth seçeneği
Açıklaması şöyle
Bu yöntem "shallow clone" diye geçer. Git clone, tüm proje geçişimini indirir ve büyük bir projede bu işlem uzun sürer. Fakat depth parametresi ile sadece en güncel versionu indirerek süreci hızlandırabilirsiniz.
Örnek
Sadece belli bir derinlikteki dosyaları indirmek için şöyle yaparız.
git clone https://github.com/user/repository --depth 1 --branch=master ~/dir-name
--recursive seçeneği
Örnek

Şöyle yaparız.
git clone --recursive -c core.longpaths=true -j 20 https://a.b.c .

Personal Access Token
Örnek
Önce şöyle yaparız. Git bize şifre ile giriş yapamayacağımızı belirtir. Personal Access Token (PAT) kullanmak gerekir.
git config --global user.name "..."
git config --global user.email "..."

git clone https://github.com/foo.git
PAT yarattıktan sonra şöyle yaparız. Bu PAT nesnenin etkinleştirilmediği anlamına gelir. Hata mesajındaki adrese tarayıcı ile gider ve etkinleştiririz.
git clone https://github.com/foo.git
Cloning into '...'...
Username for 'https://github.com': ...
Password for 'https://...':

The `Foo' organization has enabled or enforced SAML SSO. To access
this repository, visit https://github.com/orgs/...
and try your request again.
unable to access 'https://foo.git/': The requested URL returned error: 403
Daha sonra normal git clone işleminde şifre alanına PAT gireriz. Eğer  kullanıcı ismi ve PAT'i bir daha girmek istemiyorsak şöyle yaparız
git config --global credential.helper store
Daha sonra son bir defa "git pull" yaparız. Tekrar kullanıcı ismi ve şifre istenir. Yine kullanıcı ve PAT'i gireriz ve bir daha artık sormaz

18 Şubat 2022 Cuma

Git Örneklerim

Giriş
Git'i komut satırından kullanması bence oldukça zor. Bazı kullanımlarını not almak istedim
git push yazılarına bakabilirsiniz

Örnek - Push To Remote Repository
GitHub üzerinden yeni bir repository yarattım. Yeni repository'de main isimli bir branch yaratıldı.
Sonra şöyle yaptım
> git remote set-url origin https://github.com/hazelcast/hazelcast-cloud-postgre-sample
> git push origin master 
Sonra yeni repostory'de iki tane branch olduğunu fark ettim. Bunlar main ve master. Aslında ben yerel repository'imi main ismiyle gönderecektim yani şöyle yapacaktım ama dikkat etmemişim
> git push origin master:main
main branch'i sileyim dedim. Şöyle yaptım ama hata verdi
> git push origin --delete main
To https://github.com/hazelcast/hazelcast-cloud-postgre-sample
 ! [remote rejected] main (refusing to delete the current branch: refs/heads/main)
error: failed to push some refs to 'https://github.com/hazelcast/hazelcast-cloud-postgre-sample'
Çünkü main branch default branch olduğu için GitHub silmeye izin vermiyor. Önce default branch'i master yapmak gerekti. Settings sayfasından default branch'i değiştirdim. Sonra şöyle yaptım. main branch silindi
> git push origin --delete main
To https://github.com/hazelcast/hazelcast-cloud-postgre-sample
 - [deleted]         main

Örnek - Feature Brach İle Çalışma
Feature branch yarat, push'la ve feature branch'i sil
#Feature için yeni branch yarat
git checkout -b feature/rw-2028 rw_22.1 #Değişiklikleri commitle git commit -a -m "rw-2028 : ..." #Değişiklikleri pushla git push #Development branch'e geç git checkout rw_22.1 #Feature branch'i sil git branch -D feature/RLWY-2028
Örnek - Commitlenmiş Dosyayı Geri Alma
Dosyayı 2 defa commitledim ama daha push etmedim. Geri almak için şöyle yaparız
git checkout 6d4b20f81f4d17bd2a93bbcbd4eab39457e600e7 Foo.java
Örnek
Commit'lenmemiş dosya isimlerini gör
git diff --name-only
Eğer her şeyi geri sarmak istersek şöyle yaparız. Undo seçenekleri burada
git reset --hard
Örnek - Rename Remote Branch
Şöyle yaparız
git checkout railway_22.1

# change a branch name
git branch -m release/22.1.0

# delete the branch with the old name on the remote repository
git push origin --delete railway_22.1

# push the branch with the correct name
git push origin -u release/22.1.0
Örnek - tag
Yerelde tag yaratıp bir şeyi denedikten sonra silmek için şöyle yaparız
# Create new tag at local
git tag release-22.0.1
...
# Delete tag
git tag -d release-22.0.1
Örnek - tag
Yerelde tag yaratıp pushlamak için şöyle yaparız
# Delete local and push
git tag release-22.0.1
git push --tags
Örnek - yeni tag
Tag silip pushlamak için şöyle yaparız
# Delete local and push
git tag -d release-22.1.0
git push --tags
Örnek - tag move
Şöyle yaparız
# delete from remote
git push origin :refs/tags/release-22.1.0

# delete from local
git tag -d release-22.1.0

# recreate at local
git tag release-22.1.0

# push to remote
git push --tags



19 Aralık 2021 Pazar

git config seçeneği

Giriş
--local, --global, --system seçeneği ile kullanılır

alias.ci
user.name
user.email
core.editor
credential.helper
gibi şeyleri atamak mümkün

user.name ve user.email
Örnek
Author vermek için şöyle yaparız
git config --local user.name "John Doe"
git config --local user.email john@doe.com
Örnek
Şöyle yaparız.
$ git config --global user.name new
$ git config --global user.email new@new.com
alias
Örnek
Alias tanımlamak için şöyle yaparız. "git commit" yerine "git ci" yazabiliriz.
git config --global alias.ci commit
git config --global alias.co checkout
...
core.editor
Örnek
Editörü vi'dan nanoya değiştirmek için şöyle yaparız
$ git config --global core.editor "nano -w"
Örnek
Editörü notepad için şöyle yaparız
$ git config --global core.editor notepad
core.sshCommand
Örnek
Şöyle yaparız
git config core.sshCommand “ssh -i ~/.ssh/id_rsa”

credential.helper
Örnek
Şifreyi bellekte 1 saat süre saklasın diye şöyle yaparız.
git config --global credential.helper "cache --timeout=3600"
Örnek
Şifrelerin nerede saklandığını görmek için şöyle yaparız
git config --system credential.helper
manager-core
Eğer manage-core yerine manager yazsaydı şifreler Windows'ta "Kimlik Bilgileri Yöneticisi" veya İngilizce olarak "Credentials Manager" içinde saklanırdı. Yani eskiden bilgiler Windows'ta saklanırdı.

Bilgileri görmek için şöyle yaparız
git credential fill
protocol=https
host=github.com
İki defa enter'a bas
Çıktı şöyle
protocol=https
host=github.com
username=...
password=...
-l seçeneği
Örnek
Ayarları listelemek için şöyle yaparız.
git config -l --show-origin
Örnek
Global ayarları listelemek için şöyle yaparız.
$ git config --global -l
veya şöyle yaparız.
$ git config -l
Çıktı olarak şunu alırız.
user.email=new@new.com
user.name=new
-f seçeneği
Örnek
Sadece submodule ile çalışıp doğru branch'e commit etmek için şöyle yaparız.
cd /path/to/your/parent/repo
git config -f .gitmodules submodule.<path>.branch <branch>