학교수업/Git

[Git] 10. Advanced Git

hwijin97 2022. 6. 13. 23:24

More tips to work with others

 

Logging/ searching / debugging

 

git grep

- Allows to easily look for where a term exists in our working directory

$ git grep -n README

- git grep vs grep (linux)

  > Much faster and more convenient than grep

  > git grep is optimized for Git repositories

--no-index : earch files in the current directory that is not managed by Git

--untracked : search both tracked & untracked files

--no-exclude-standard : search in ignored files (should be used with --untracked)

--exclude-standard : do not search in ignored files ( sould be used with --no-index)

 

git log -S

Allows to easily look for when a term existed

 

git blame

shows which commit was responsible for the introduction of certain code lines.

 

git stash

store any chages to a special stack

- All untracked, modified, and staged files are stored into the stack

- All the files are recovered by their up-to-date data (the most recently committed one)

Advanced merge

Merging two unrelated projects

 

$ git clone project A's URL

$ remote add projectB project B's URL

$ git fetch projectB

$ git checkout -b trackingB projectB/master

 

Q. What will happend if we run "git checkout master and git merge trackingB"??

- Why? : TracingB and master have no common ancestor. (they are not related)

 

$ git merge --allow-unrelated-histories [branch]