Skip to content

Minimum guide for main git commands

Marc edited this page Mar 15, 2024 · 10 revisions

New local repo

git clone https://github.com/KhiopsML/khiops.git

pre-commit install: to format the files

Branches

git branch --all: to see all branches on your local repo

git switch branch_name: to switch to your branch

Preparing a commit

git status show usefull info: current branch, and current status of modified files

  • manage the files to be added to the commit

git add -u: to take into account all updates files

git add file_name: to add a specific file

git mv file_name new_file_name: to rename a file

Making a commit

git commit

git push: to update to central repo

  • Commit message
    • first line is the title, and it should short explaining the What the commit does
    • followed by an empty line, and then detailed comments if necessary
    • good practise: use your IDE to check your changes and write a synthetic summary
  • Updating previous commit for a minor change (ex: typo)

git commit --amend

git commit --amend --no-edit: idem, without update the commit message

git push --force: required to force the update of the central repo after the amend

Rebasing a branch

You may want to refresh a branch if its origin has been updated since the branch was developed. You thus need to rebase your branch branch-name on dev to get the last version of the source

  • refresh the local repo on dev

git switch dev

git pull

  • take into account the last commit of dev

git switch branch-name

git rebase dev

  • resolve conflicts and make a commit again

Pull request

  • Prerequistes:
    • first, rebase your branch branch on dev to get the last version of the source
    • tests on the standard family will be carried out automatically using CICD
    • for major pull requests, may require all LearningTest non-regression tests to be verified

History of commit notes

git log

git log --oneline: with titles only

git log -n: last n commits

gitk: show log in UI mode

See previous versions

git log -p file_name: show last updates in shell mode

gitk file_name: in UI mode

Switch to a previous commit

git log --oneline: to see previous commit with their commit_hash

git switch -d commit_hash

Using github for temporary backups

Need: periodically save the current branch, even if it has not reached a stable state

  • make temporary commits, with the commit message prefixed with WIP (work in progress)
    • push tehm to save them on the central repo
  • once development has stabilised, merge these temporary commits into a single commit (squash)
    • First of all, you need to get the sha1 (commit_hash) of the commit preceding the one you are going to squash
      • using git log --oneline
    • then use it to run the command: git rebase -i commit_hash
    • You then enter interactive mode (using the git editor).
      • Commits are displayed from the oldest to the most recent.
      • The first commit is the basic one, the one you want to keep; so leave the "pick" instruction in front of it.
      • We want to squash all subsequent commits, so we put the "squash" instruction in front of them.
    • In concrete terms, we tell GIT to base itself on the first commit and we apply all the subsequent commits to make just one.
    • When you validate the squash (you leave interactive mode), Git will re-apply the commits in the same order as they were configured just before. We then put in a commit message relating to the grouping of our commits (from the messages for the relevant commits) and that's all.
  • When the final commit is pushed, you need to force it: git push --force
Clone this wiki locally