0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ローカルGit

0
Posted at

今回の記事
Azureの記事を書く機会が増えて、開発をしていると、「Git」に触れることが多くて、少し整理が必要かと思い、「Git」を題材にしました。ターゲットは以下です。
 ・Windowsで開発(Dotnet-C#、React)をする場合
 ・少人数ながら複数人で開発を目指す
 ・プログラムはDevOpsで管理する

初回のDevOpsへのプログラムのアップロード
まずは、ローカルに開発言語のプロジェクトを作成した後、プログラムを DevOps へ Push する時です。PowerShellで、プロジェクトのフォルダをカレントディレクトリにして、以下のコマンドを実行します。

1) git init
2) git remote add origin http 〇〇〇〇〇〇〇
3) git config --global user.〇〇〇〇〇〇〇
4) git add .
5) git commit -m "初回コミット等のコメント"
6) git branch  (ブランチの確認:masterの場合)
7) git push -u origin master

1)カレントディレクトリ内に 隠しディレクトリ である「.git」が作成されます。
2)どこのDevOpsの中のプロジェクトに、プログラムを Push するかを指定します。
 http の URL 部分は、DevOpsで確認が可能です。
image.png
 「origin」の部分はエイリアスで、変更可能な名称のようですが、Aiが「origin」で勉強している事が多いようで、変更しない方が理解しやすい気がしました。
3)少し毛色が違いますが「--global」があるので、操作しているパソコン全てのプロジェクトで有効な設定変更です。推奨としては、以下の2つを設定します。
  ・git config --global user.name "名前"
  ・git config --global user.email "メールアドレス"
 この設定で、誰が更新したのかを明確に記録することが可能です。
4)このコマンドで、更新内容を準備します
5)このコマンドで、更新内容を確定し、正式な更新履歴として管理ます
6)どのブランチへアップするかを確認します
 (作業中のブランチには「*」が付与されます)
7)COMMIT された内容を、DevOps へアップロードします。
 「-u」をする事で、次回以降の push/pull は、ブランチを指定する必要がなくなります。

2回目以降のアップロード
初回の Push 以降、テストした後、不具合などが見つかり即改修&デプロイするのであれば、

1) git add .
2) git commit -m "どんな不具合対応をしたかのコメント"
3) git push

これで十分です。ただ、初回の Push 後、仕様変更までに期間が空いてしまうと、誰かがプログラムを変更したかもしれません。
そんな時は、このコマンドで、最新のプログラムを取得してから改修しましょう。

0) git pull

2回目以降でアップロードしたら何か別の更新がされていた場合
以下のようなエラーが出ます。(エラーなので、push されていません)

> git push
To http 〇〇〇〇〇〇〇
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'http 〇〇〇〇〇〇〇'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

この時、以下のパラメータで、ローカルへ Pull してみます。
(CONFLICT=コンフリクト=競合=同じプログラムを更新しているって事)
問題のプログラムは「src/App.js」です。

> git pull --no-rebase
Auto-merging src/App.js
CONFLICT (content): Merge conflict in src/App.js
Automatic merge failed; fix conflicts and then commit the result.

コンフリクトが発生しているプログラム「src/app.js」を開くと、内容が確認できます。
image.png
※ 全角文字が化けている可能性もあります…
プログラムを正しく修正した後は、

git add src/App.js
git commit  (画面が切り替わりますが、「:q!」で終了させることが可能でした)
git push

これで、DevOps へ Push が可能でした。

最後に
今回「GIT」コマンドだけ整理しましたが、Node にしても、Dotnet にしても、色々なコマンドを使っている気がします。
コマンドだと、Ai が全て回答してくれるので、迷うことは無いですが、色々あり過ぎて全てを記憶するのは、かなり面倒ですね。(これも歳の為でしょうか!?)
以上、お疲れさまでした~。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?