LỆNH GIT QUAN TRỌNG (GIT COMMAND)


Set your details

git config --global user.name "John Doe"
git config --global user.email "john@example.com"
Use --global to set the configuration for all projects. If git config is used without --global and run inside a project directory, the settings are set for the specific project.

Make git ignore file modes

cd project/
git config core.filemode false
This option is useful if the file permissions are not important to us, for example when we are on Windows.

See your settings

git config --list

Initialize a git repository for existing code

cd existing-project/
git init

Clone a remote repository

git clone https://github.com/user/repository.git
This creates a new directory with the name of the repository.

Clone a remote repository in the current directory

git clone https://github.com/user/repository.git .

Get help for a specific git command

git help clone

Update and merge your current branch with a remote

cd repository/
git pull origin master
Where origin is the remote repository, and master the remote branch.
If you don't want to merge your changes, use git fetch

View remote urls

git remote -v

Change origin url

git remote set-url origin http//github.com/repo.git

Add remote

git remote add remote-name https://github.com/user/repo.git

See non-staged (non-added) changes to existing files

git diff
Note that this does not track new files.

See staged, non-commited changes

git diff --cached

See differences between local changes and master

git diff origin/master
Note that origin/master is one local branch, a shorthand for refs/remotes/origin/master, which is the full name of the remote-tracking branch.

See differences between two commits

git diff COMMIT1_ID COMMIT2_ID

See the files changed between two commits

git diff --name-only COMMIT1_ID COMMIT2_ID

See the files changed in a specific commit

git diff-tree --no-commit-id --name-only -r COMMIT_ID
or
git show --pretty="format:" --name-only COMMIT_ID

See diff before push

git diff --cached origin/master

See details (log message, text diff) of a commit

git show COMMIT_ID

Check the status of the working tree (current branch, changed files...)

git status

Make some changes, commit them

git add changed_file.txt
git add folder-with-changed-files/
git commit -m "Commiting changes"

Rename/move and remove files

git rm removeme.txt tmp/crap.txt
git mv file_oldname.txt file_newname.txt
git commit -m "deleting 2 files, renaming 1"

Change message of last commit

git commit --amend -m "New commit message"

Push local commits to remote branch

git push origin master

See recent commit history

git log

See commit history for the last two commits

git log -2

See commit history for the last two commits, with diff

git log -p -2

See commit history printed in single lines

git log --pretty=oneline

Revert one commit, push it

git revert dd61ab21
git push origin master

Revert to the moment before one commit

# reset the index to the desired tree
git reset 56e05fced

# move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}

git commit -m "Revert to 56e05fced"

# Update working copy to reflect the new commit
git reset --hard

Undo last commit, preserving local changes

git reset --soft HEAD~1

Undo last commit, without preserving local changes

git reset --hard HEAD~1

Undo last commit, preserving local changes in index

git reset --mixed HEAD~1
Or git reset HEAD~1
See also http://stackoverflow.com/q/927358/1391963

Undo non-pushed commits

git reset origin/master

Reset to remote state

git fetch origin
git reset --hard origin/master

See local branches

git branch

See all branches

git branch -a

Make some changes, create a patch

git diff > patch-issue-1.patch

Add a file and create a patch

git add newfile
git diff --staged > patch-issue-2.patch

Add a file, make some changes, and create a patch

git add newfile
git diff HEAD > patch-issue-2.patch

Make a patch for a commit

git format-patch COMMIT_ID

Make patches for the last two commits

git format-patch HEAD~2

Make patches for all non-pushed commits

git format-patch origin/master

Create patches that contain binary content

git format-patch --binary --full-index origin/master

Apply a patch

git apply -v patch-name.patch

Apply a patch created using format-patch

git am patch1.patch

Create a tag

git tag 7.x-1.3

Push a tag

git push origin 7.x-1.3

Create a branch

git checkout master
git branch new-branch-name
Here master is the starting point for the new branch. Note that with these 2 commands we don't move to the new branch, as we are still in master and we would need to run git checkout new-branch-name. The same can be achieved using one single command: git checkout -b new-branch-name

Checkout a branch

git checkout new-branch-name

See commit history for just the current branch

git cherry -v master
(master is the branch you want to compare)

Merge branch commits

git checkout master
git merge branch-name
Here we are merging all commits of branch-name to master.

Merge a branch without committing

git merge branch-name --no-commit --no-ff

See differences between the current state and a branch

git diff branch-name

See differences in a file, between the current state and a branch

git diff branch-name path/to/file

Delete a branch

git branch -d new-branch-name

Push the new branch

git push origin new-branch-name

Get all branches

git fetch origin

Get the git root directory

git rev-parse --show-toplevel

Remove from repository all locally deleted files

git rm $(git ls-files --deleted)

Delete all untracked files

git clean -f
Including directories:
git clean -f -d
Preventing sudden cardiac arrest:
git clean -n -f -d

Show total file size difference between two commits

Short answer: Git does not do that.
Long answer: See http://stackoverflow.com/a/10847242/1391963

Unstage (undo add) files:

git reset HEAD file.txt

See closest tag

git describe --tags `git rev-list --tags --max-count=1`
Source. See also git-describe.

Have git pull running every X seconds, with GNU Screen

screen
for((i=1;i<=10000;i+=1)); do sleep 30 && git pull; done
Use Ctrl+a Ctrl+d to detach the screen.

See previous git commands executed

history | grep git
or
grep '^git'  /root/.bash_history

See recently used branches (i.e. branches ordered by most recent commit)

git for-each-ref --sort=-committerdate refs/heads/ | head

Tar project files, excluding .git directory

cd ..
tar cJf project.tar.xz project/ --exclude-vcs

Tar all locally modified files

git diff --name-only | xargs tar -cf project.tar -T -

Look for conflicts in your current files

grep -H -r "<<<" *
grep -H -r ">>>" *
grep -H -r '^=======$' *
There's also git-grep.

Apply a patch not using git:

patch < file.patch

Add file ignore:

git add -f "duongdanthumuc chua cac file js"

Clone branch

git clone -b gh-pages "https://github.com/user/xxx.git"

Switch branch

git checkout -b namebranch

Delete htaccess file

 git add -f .htaccess
git add

  • git add -A . or git add --all    :stages All
  • git add .    :stages new and modified, without deleted (include folder current, and subfolder)
  • git add * : stages new and modified, without deleted and folder or file begin with dot
  • git add -u .    :stages modified and deleted, without new

Nguồn  https://orga.cat/posts/most-useful-git-commands



Related

Organic Search And Keywords

SEO nếu được thực hiện đúng là một trong những hình thức rẻ nhất của tiếp thị. Khán giả đã có trong tìm kiếm cho các sản phẩm hoặc dịch vụ. Mặc dù SEO là cái gì đó là thạo việc tốt hơn so với dạy ...

Logo Supercharger Pack 1

Nếu bạn đã bao giờ muốn để thêm vào cuộc sống và năng lượng cho một biểu tượng trong video của bạn, Blue FX Logo supercharger trọn gói có thể giúp bạn đạt được nó. Gói này chứa TEN hình ảnh động ...

Photo Restoration Techniques: Color Casts and Fading

Các cụm từ "phục hồi hình ảnh" gợi lên hình ảnh của rách gốc-ảnh bị rách và / hoặc đã phai mờ gần như không còn nhận ra. Tuy nhiên, nhiều bức ảnh cổ điển có những thử thách đơn giản, chẳng hạn như...

Post a Comment Default Comments

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

RecentPopularComments

Recent

Cài đặt Wordpress trên localhost với XAMPP (Install wordpress on localhost with XAMPP)

Bước 1:Bạn cài đặt XAMPP và download Wordpress tại địachỉ https://wordpress.org/download/ về máy tính của mình Bước 2: Giải nén thư mục Wordpress vừa download và chép vào thư mục htdocs của...

Fix lỗi mở file Power Point (How to Solve “PowerPoint Found a Problem with Content” Error)

Khi bạn mở file Power Point lên mà bị thống báo lỗi này Click Repair thử  Vẫn không được !!!! Để giải quyết trường hợp này mình sẽ có 2 cách để khắc phục Cách 1: Bạn làm như sau Tắ...

Resources for IT (Collect somewhere on Internet)

Resources include link download tools, software, code for IT default-facebook

Xoá các file đã mở gần đây trong Photoshop CC (Delete Recent file list on Photoshop CC)

Nếu như bạn đã làm việc hay thao tác với một số file trên Photoshop. Khi tắt Photoshop, mở lại dùng nó vào lần sau, thì khi mở lên Photoshop sẽ hiện danh sách các file bạn đã thao tác , làm việc cùng ...

Responsive fontsize text trong html5 một cách dễ dàng (How to responsive fontsize text in html5)

Trước tiên, ta phải tìm hiểu sơ qua một số đơn vị trong html5. Ngoài đơn vị pixel ra thì có một số đơn vị hay sử dụng: Đơn vị : em  Ví dụ có element div1 chứa div2, div1 có font-size:14px ...

Resources for designer (Collect somewhere on Internet)

Resources include link download stock, plugin, tool... for designer. default-facebook

Set up chiều rộng của các cột trong table bằng nhau chỉ bằng một thuộc tính trong css (Set column of table same width by css)

Bài viết này mình xin demo 1 trick để set up chiều rộng của thẻ td trong table html5 chỉ bằng một thuộc tính. Ở đây ví dụ mình có cái bảng viết bằng code html5 giao diện như sau Có tổng cộng 3 cộ...

Comments

Diễn Đàn Gaming:

SELLVIA24H.TOP - Latest news from the United States

Intern TOS:

github là gì Có thể nhiều người không biết github là gì ấy chứ, GitHub là một nơi để lưu trữ và quản lý mã nguồn cho các dự án phần mềm. GitHub có cả phiên bản miễn phí và trả phí, với phiên bản miễn ...

Intern TOS:

This comment has been removed by the author.

Like Us!

item