0

I want to do a script that help me to release a system by checkout a repo in GIT.

My quest is can I some way test to checkout a branch to identify if I got error without to rely do this on the file-system.

As same, can I on a easy way preview a GIT merge for identify conflict without modify the file-system?

(The full system is run on Linux system if this is to help)

eckes
  • 64,417
  • 29
  • 168
  • 201
FIG-GHD742
  • 2,486
  • 1
  • 19
  • 27

2 Answers2

1

Use git merge --ff-only - it will merge branch only if it could be fast forwarded. It means that conflicts are impossible and it will always work (except of course system failures, e.g. out of disk space). Obviously, it means that branches should be not diverged, however in most cases it is so, if not you should do merge with potential conflicts in another repo, keeping the "release repo" untouched.

Another approach here is to use symlinks (linux or ntfs). You should have two repositories repo1 and repo2 and a symlink releaserepo which will point to one of these. Say, you have releaserepo->repo1. Now you could update repo2, check if all works, then just change symlink to it, next time you will update repo1 and flip the symlink back. If will avoid all system failures too, because create symlink operation is atomic.

kan
  • 28,279
  • 7
  • 71
  • 101
0

If you checkout a branch, you'll never get an error. The checkout just restores the previous state of the branch.

Things get different, if you want to check merges.

If you have a branch mybranch and you want to merge otherbranch into it, remember the state of mybranch before the merge:

git log -1 --oneline

This returns the hash of the last commit. Note that hash (e.g. CAFEBABE).

Now, try to do the merge:

git merge otherbranch

If everything works. Fine. If you get any errors and are not willing to resolve them:

git reset --hard CAFEBABE

This will reset mybranch to the state before git merge was done.

Instead of remembering the hash CAFEBABE, you could also make use of ORIG_HEAD as described here: HEAD and ORIG_HEAD in Git

Community
  • 1
  • 1
eckes
  • 64,417
  • 29
  • 168
  • 201