Skip to content

Latest commit

 

History

History
204 lines (160 loc) · 3.5 KB

git.md

File metadata and controls

204 lines (160 loc) · 3.5 KB

git

Sources

https://docs.freebsd.org/en/articles/committers-guide/#git-primer

Diff

Diff from a specific hash:

git diff b97a47e94662^!

Create a patch from a specific hash:

git format-patch b5711fa4a98^!

Apply git patch

Preserving original author name, and tunning commit if it needs:

git am file.patch
git commit --amend

Find data

date

When was the branch branched ?

$ git show --summary `git merge-base working-branch-name main`
commit xxxxxx
Merge: yyyyy
Author: root
Date:   Wed May 24 19:13:34 2023 +0000

    Pull request #????: branch-xxx

    Merge in xxx/yyy from branch-zzz to main

    * commit 'xxxx'
      blah.

When was that file detele?

git log --all -1 -- path/to/file

What version was patched:

git -C /usr/src rev-list --count --first-parent HEAD

patch?

Keeping working branch up-to-date with origin

Create a new branch:

git checkout -b new-branch

hack....

push changes:

git push origin -u new-branch

But now, need to get new commit from the origin:

git switch new-name
git fetch origin
git rebase

=> resolve conflict (and commit it!) then git rebase --continue

git push

Squash multiples commit in one

Display all last commits to be squashed:

git log --pretty=oneline

Let’s use an example of 5 last commits here:

git rebase -i HEAD~5

First text editor that open:

  • first line, kept the 'pick' keyword
  • all others 4 lines: Replace 'pick' by 's' (squash) => save & exit
  • Adapt the squashed commit message => save & exit

Now push back your rebase:

git push origin +branch-name

Revert a rebase

You’ve squashed a wrong commit, so your rebase need to be reverted.

git reset --hard origin/branch-name

Forking FreeBSD port

From git webui: Fork freebsd/freebsd-ports

clone forked

git clone [email protected]:ocochard/freebsd-ports.git

git clone [email protected]:ocochard/freebsd-src.git

cd freebsd-ports

Add upstream

git remote add upstream [email protected]:freebsd/freebsd-ports

Therminology:

  • Origin = own fork
  • upstream = FreeBSD official
  • main = name of the main branch (was called 'master' previously)

Creating a BSDRP branch

git checkout -b BSDRP
=> hack
git commit

Sending this local-only branch to upstream, need to create it remotely the first time:

git push -u origin BSDRP
=> hack
git commit
git push

keeping BSDRP branch with main up-to-date

Need to start with the main branch, then the BSDRP

git checkout main
git pull
git checkout branch-name
git rebase main
git push -f

=> Now, local main is up-to-date with upstream

git checkout BSDRP
#git rebase main
git pull --rebase upstream/main ?, this one is equivalent to git fetch + git rebase origin/master
git push

Or sync WIP branch with the main:

git checkout WIP
git rebase master WIP

Cherry pick

git remote add motoprogger [email protected]:motoprogger/FreeVRRPd.git
git checkout <branch>
git fetch motoprogger
git cherry-pick <commit-hash>
git push <your-fork-alias>

Taging a new release

git tag -a v1.992 -m "Releasing version v1.992"
git push origin v1.992

Branch

Deleting

Local and remote:

git branch -d branch-name
git push origin -d branch-name

Reset all local change and replace with remote

@{u} is shorthand for upstream branch

git reset --hard @{u}