Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Cách sử dụng Git
  6. Cách quản lý lịch sử trong Gi
  7. Kết hợp các cam kết
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Kết hợp các cam kết

Đi đến thư mục git-tutorial/tutorial5 mà bạn đã tải xuống trước đó.

Khi bạn kiểm tra lịch sử của kho lưu trữ này, nó sẽ giống như sau:

Current history

Chúng tôi sẽ kết hợp hai cam kết, “append description of the commit command” và “append description of the pull command” thành một cam kết duy nhất.

Để làm điều đó, chúng ta sẽ sử dụng lệnh git rebase -i.

$ git rebase -i HEAD~~

Khi trình soạn thảo văn bản mặc định của bạn mở ra, bạn sẽ ở chế độ rebase-interactive. Nó sẽ hiển thị các cam kết từ HEAD đến HEAD~~, như hình bên dưới:

pick 9a54fd4 append description of the commit command
  pick 0d4a808 append description of the pull command

  # Rebase 326fc9f..0d4a808 onto d286baa
  #
  # Commands:
  #  p, pick = use commit
  #  r, reword = use commit, but edit the commit message
  #  e, edit = use commit, but stop for amending
  #  s, squash = use commit, but meld into previous commit
  #  f, fixup = like "squash," but discard this commit log message
  #  x, exec = run command (the rest of the line) using shell
  #
  # If you remove a line here THAT COMMIT WILL BE LOST.
  # However, if you remove everything, the rebase will be aborted.
  #

Ở dòng thứ hai, thay từ pick bằng squash, sau đó lưu và thoát.

Trình chỉnh sửa sau đó sẽ nhắc bạn chỉnh sửa tin nhắn cam kết của cam kết mới được tạo này. Chỉnh sửa tin nhắn cam kết, sau đó lưu và thoát.

Hai cam kết trước đó hiện được gộp thành một cam kết mới.

Xác minh kết quả bằng cách kiểm tra nhật ký lịch sử bằng lệnh git log.

Organize commit

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life